Class: Yadriggy::Call
- Includes:
- AstHelper
- Defined in:
- lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb
Overview
Method call following parentheses.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Array<ASTnode>
readonly
The method-call arguments.
-
#block ⇒ ASTnode|nil
readonly
The block passed to the method.
-
#block_arg ⇒ ASTnode|nil
readonly
The argument preceded by an ampersand.
-
#name ⇒ Identifier
readonly
The method name.
-
#op ⇒ Symbol
readonly
Returns either
:"."
,:"::"
, ornil
. -
#receiver ⇒ ASTnode|nil
readonly
The callee object.
Attributes inherited from ASTnode
Class Method Summary collapse
-
.make(receiver: nil, op: nil, name:, args: [], block_arg: nil, block: nil, parent:, link_from_children: false) ⇒ Call
Makes an instance of Call with the given values for its instance variables.
- .tags ⇒ Object
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
-
#initialize(sexp) ⇒ Call
constructor
A new instance of Call.
-
#value ⇒ Object
Gets the invoked method or Undef.
- #value_in_class(klass) ⇒ Object
Methods included from AstHelper
#has_tag?, #to_node, #to_nodes
Methods inherited from ASTnode
#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string
Constructor Details
#initialize(sexp) ⇒ Call
Returns a new instance of Call.
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
# File 'lib/yadriggy/ast.rb', line 863 def initialize(sexp) @args = [] @block_arg = nil @block = nil case sexp[0] when :call, :field initialize_call(sexp) when :method_add_block marg = sexp[1] if marg[0] == :method_add_arg initialize_method_arg(marg[1], marg[2]) elsif marg[0] == :command initialize_call([:call, nil, nil, marg[1]]) initialize_args(marg[2]) if marg.length > 2 elsif marg[0] == :command_call initialize_call([:call, marg[1], marg[2], marg[3]]) initialize_args(marg[4]) if marg.length > 4 else initialize_method_arg(marg, []) end @block = to_node(sexp[2]) add_child(@block) else initialize_method_arg(sexp[1], sexp[2]) end end |
Instance Attribute Details
#args ⇒ Array<ASTnode> (readonly)
Returns the method-call arguments.
813 814 815 |
# File 'lib/yadriggy/ast.rb', line 813 def args @args end |
#block ⇒ ASTnode|nil (readonly)
Returns the block passed to the method.
819 820 821 |
# File 'lib/yadriggy/ast.rb', line 819 def block @block end |
#block_arg ⇒ ASTnode|nil (readonly)
Returns the argument preceded by an ampersand.
816 817 818 |
# File 'lib/yadriggy/ast.rb', line 816 def block_arg @block_arg end |
#name ⇒ Identifier (readonly)
Returns the method name.
810 811 812 |
# File 'lib/yadriggy/ast.rb', line 810 def name @name end |
#op ⇒ Symbol (readonly)
Returns either :"."
, :"::"
, or nil
.
807 808 809 |
# File 'lib/yadriggy/ast.rb', line 807 def op @op end |
#receiver ⇒ ASTnode|nil (readonly)
Returns the callee object.
801 802 803 |
# File 'lib/yadriggy/ast.rb', line 801 def receiver @receiver end |
Class Method Details
.make(receiver: nil, op: nil, name:, args: [], block_arg: nil, block: nil, parent:, link_from_children: false) ⇒ Call
Makes an instance of Yadriggy::Call with the given values for its instance variables.
833 834 835 836 837 838 839 |
# File 'lib/yadriggy/ast.rb', line 833 def self.make(receiver: nil, op: nil, name:, args: [], block_arg: nil, block: nil, parent:, link_from_children: false) obj = self.allocate obj.initialize2(receiver, op, name, args, block_arg, block, parent, link_from_children) end |
.tags ⇒ Object
861 |
# File 'lib/yadriggy/ast.rb', line 861 def self.() [:method_add_arg, :call, :method_add_block, :field] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
894 895 896 |
# File 'lib/yadriggy/ast.rb', line 894 def accept(evaluator) evaluator.call(self) end |
#value ⇒ Object
Gets the invoked method or Undef.
397 398 399 400 401 402 403 |
# File 'lib/yadriggy/ast_value.rb', line 397 def value() if @receiver.nil? lookup_method(get_receiver_object) else lookup_method(@receiver.value) end end |
#value_in_class(klass) ⇒ Object
405 406 407 408 409 410 411 |
# File 'lib/yadriggy/ast_value.rb', line 405 def value_in_class(klass) if @receiver.nil? lookup_method(get_receiver_object) else lookup_method(@receiver.value_in_class(klass)) end end |