Ruby Ripper is a core library as of Ruby 1.9 that takes ruby input and produces s-expressions.
Questions tagged [ruby-ripper]
7 questions
9
votes
1 answer
How would I recompile Ripper's AST back to Ruby code?
Ripper is the the parsing library that ships with Ruby 1.9. It transforms Ruby code into an AST, like so:
pp Ripper.sexp("def foo; yield :a; return 1 end")
#=>
[:program,
[[:def,
[:@ident, "foo", [1, 4]],
[:params, nil, nil, nil, nil,…

Jon Smock
- 9,451
- 10
- 46
- 49
6
votes
2 answers
What is the meaning of the 'send' keyword in Ruby's AST?
I am trying to learn the Ruby lexer and parser (whitequark parser) to know more about the procedure to further generate machine code from a Ruby script.
On parsing the following Ruby code string.
def add(a, b)
return a + b
end
puts add 1, 2
It…

pravj
- 300
- 3
- 10
1
vote
1 answer
detecting errors during ruby ripper parsing
Has anyone figured out how to detect errors when malformed input is given to Ruby's ripper library?
ruby-1.9.2-p180 :002 > Ripper.sexp("array[1 2]")
=> [:program, [:@int, "2", [1, 8]]]
ruby-1.9.2-p180 :003 >
I've poked around the sources a little…

Eric Walker
- 7,063
- 3
- 35
- 38
1
vote
1 answer
Safe to parse user submitted code using Ripper?
I'm using the Ruby 1.9 Ripper library to analyze specific parts of a source code by building it's sexp tree. From what I know, Ripper just uses a lexer / parser to do this.
Is it safe to run Ripper on a user submitted code?

Dogbert
- 212,659
- 41
- 396
- 397
1
vote
1 answer
Ruby ripper.bundle incompatible library version errors after system restore from backup
After having to restore my whole system from a backup I'm having trouble with my Ruby gems. In particular, I get "incompatible library version" errors in relation to ripper.bundle.
Have tried:
Reinstalling rbenv via homebrew
Reinstalling Ruby via…

Rob Lucas
- 81
- 3
0
votes
1 answer
Using ripper in a rails app?
I want to check the source of a file (maybe a view) if it contains logic, so I thought of using Ripper.lex but I'm not sure if it's possible to pass a file to .lex and it will read the code IN the file.
Like if I have source.rb or source.haml.erb,…

kimsanity
- 17
- 3
-1
votes
1 answer
Parse ruby code
I need help in one problem. I have a table with columns that contain some ruby code, like this: self.org_premium = self.volume / 12 * 0.1492 self.billing_premium = self.subscriber_premium + self.org_premium or employment_level == 'P' or…

Nike0
- 55
- 1
- 9