Class: Cry::Codegen::RubyMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/cry/codegen/ruby_method.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, arg_names = [], source = nil) ⇒ RubyMethod

Returns a new instance of RubyMethod.



8
9
10
11
12
# File 'lib/cry/codegen/ruby_method.rb', line 8

def initialize(name = nil, arg_names = [], source = nil)
  @name = name
  @arg_names = arg_names
  @source = source
end

Instance Attribute Details

#arg_namesObject

Returns the value of attribute arg_names.



6
7
8
# File 'lib/cry/codegen/ruby_method.rb', line 6

def arg_names
  @arg_names
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/cry/codegen/ruby_method.rb', line 6

def name
  @name
end

#sourceObject

Returns the value of attribute source.



6
7
8
# File 'lib/cry/codegen/ruby_method.rb', line 6

def source
  @source
end

Class Method Details

.extract_arg_names(exp) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/cry/codegen/ruby_method.rb', line 21

def extract_arg_names(exp)
  arg_names = []
  if exp[2][0] == :paren && (exp[2][1][0] == :params)
    exp[2][1][1].each do |arg|
      arg_names << arg[1] if arg[0] == :@ident
    end
  end
  arg_names
end

.new_from_sexp(name, exp) ⇒ Object



15
16
17
18
19
# File 'lib/cry/codegen/ruby_method.rb', line 15

def new_from_sexp(name, exp)
  source = Sorcerer.source(exp, multiline: true, indent: true)
  arg_names = extract_arg_names(exp)
  RubyMethod.new(name, arg_names, source)
end