Class: Code::Object::RubyFunction

Inherits:
Function show all
Defined in:
lib/code/object/ruby_function.rb

Instance Attribute Summary collapse

Attributes inherited from Function

#body, #parameters

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

#call, #inspect, #signature_for_call, #to_s

Methods inherited from Code::Object

#<=>, #==, call, #call, #code_and_operator, code_and_operator, #code_different, code_different, code_equal_equal, #code_equal_equal, #code_equal_equal_equal, code_equal_equal_equal, code_exclamation_point, #code_exclamation_point, code_exclusive_range, #code_exclusive_range, code_inclusive_range, #code_inclusive_range, code_or_operator, #code_or_operator, code_self, #code_self, code_to_string, #code_to_string, #falsy?, falsy?, hash, #hash, maybe, multi_fetch, #multi_fetch, repeat, #sig, sig, to_s, #to_s, truthy?, #truthy?, |

Constructor Details

#initialize(raw) ⇒ RubyFunction

Returns a new instance of RubyFunction.



8
9
10
# File 'lib/code/object/ruby_function.rb', line 8

def initialize(raw)
  @raw = raw
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



6
7
8
# File 'lib/code/object/ruby_function.rb', line 6

def raw
  @raw
end

Class Method Details

.nameObject



12
13
14
# File 'lib/code/object/ruby_function.rb', line 12

def self.name
  "RubyFunction"
end

Instance Method Details

#code_call(args:, globals:) ⇒ Object

TODO: fix / refactor



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/code/object/ruby_function.rb', line 17

def code_call(args:, globals:)
  regular_arguments =
    args
      .select(&:regular?)
      .map(&:value)
      .map { |argument| Ruby.from_code(argument) }

  keyword_arguments =
    args
      .select(&:keyword?)
      .map do |argument|
        [argument.name.to_sym, Ruby.from_code(argument.value)]
      end
      .to_h

  Ruby.to_code(raw.call(*regular_arguments, **keyword_arguments))
end