Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/melbourne.rb

Instance Method Summary collapse

Instance Method Details

#to_ast(name = '(eval)', line = 1) ⇒ Object

Creates an AST for a String containing Ruby source code.

Examples:

Converting Ruby code in a string to an AST


'class Test; end'.to_ast # => <AST::Class:0x1017800f8...

Parameters:

  • name+ (String)

    the name of the source (this is usuall the name of the file the code was read from); defaults to (eval)

  • line (Fixnum) (defaults to: 1)

    the starting line (if it’s not 1 for some reason); defaults to 1



21
22
23
# File 'lib/melbourne.rb', line 21

def to_ast(name = '(eval)', line = 1)
  Melbourne::Parser.parse_string(self, name, line)
end