Class: Yadriggy::Def
- Inherits:
-
Parameters
- Object
- ASTnode
- Parameters
- Yadriggy::Def
- Defined in:
- lib/yadriggy/ast.rb
Overview
Method definition or a singular method definition.
Instance Attribute Summary collapse
-
#body ⇒ Exprs|ASTnode
readonly
The body.
-
#name ⇒ Identifier
readonly
The method name.
-
#rescue ⇒ Rescue|nil
readonly
The rescue clause.
-
#singular ⇒ ASTnode|nil
readonly
The object if the definition is a singular method.
Attributes inherited from Parameters
#block_param, #keywords, #optionals, #params, #params_after_rest, #rest_of_keywords, #rest_of_params
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
-
#initialize(sexp) ⇒ Def
constructor
A new instance of Def.
Methods inherited from Parameters
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, #value, #value_in_class
Constructor Details
#initialize(sexp) ⇒ Def
Returns a new instance of Def.
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 |
# File 'lib/yadriggy/ast.rb', line 1585 def initialize(sexp) if sexp[0] == :def @singular = nil offset = 0 else @singular = to_node(sexp[1]) add_child(@singular) offset = 2 end def_name = sexp[1 + offset] @name = if def_name[0] == :@op to_node(def_name) else to_node(has_tag?(def_name, :@ident)) end add_child(@name) params = sexp[2 + offset] if !params.nil? && params[0] == :paren super(params[1]) else super(params) end bodystmt = has_tag?(sexp[3 + offset], :bodystmt) @body = Exprs.make(bodystmt[1]) @rescue = Rescue.make(bodystmt[2], bodystmt[3], bodystmt[4]) add_child(@body) add_child(@rescue) end |
Instance Attribute Details
#body ⇒ Exprs|ASTnode (readonly)
Returns the body.
1579 1580 1581 |
# File 'lib/yadriggy/ast.rb', line 1579 def body @body end |
#name ⇒ Identifier (readonly)
Returns the method name.
1577 1578 1579 |
# File 'lib/yadriggy/ast.rb', line 1577 def name @name end |
#rescue ⇒ Rescue|nil (readonly)
Returns the rescue clause.
1581 1582 1583 |
# File 'lib/yadriggy/ast.rb', line 1581 def rescue @rescue end |
#singular ⇒ ASTnode|nil (readonly)
Returns the object if the definition is a singular method.
1575 1576 1577 |
# File 'lib/yadriggy/ast.rb', line 1575 def singular @singular end |
Class Method Details
.tags ⇒ Object
1583 |
# File 'lib/yadriggy/ast.rb', line 1583 def self.() [:def, :defs] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
1620 1621 1622 |
# File 'lib/yadriggy/ast.rb', line 1620 def accept(evaluator) evaluator.define(self) end |