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.
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 |
# File 'lib/yadriggy/ast.rb', line 1569 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.
1563 1564 1565 |
# File 'lib/yadriggy/ast.rb', line 1563 def body @body end |
#name ⇒ Identifier (readonly)
Returns the method name.
1561 1562 1563 |
# File 'lib/yadriggy/ast.rb', line 1561 def name @name end |
#rescue ⇒ Rescue|nil (readonly)
Returns the rescue clause.
1565 1566 1567 |
# File 'lib/yadriggy/ast.rb', line 1565 def rescue @rescue end |
#singular ⇒ ASTnode|nil (readonly)
Returns the object if the definition is a singular method.
1559 1560 1561 |
# File 'lib/yadriggy/ast.rb', line 1559 def singular @singular end |
Class Method Details
.tags ⇒ Object
1567 |
# File 'lib/yadriggy/ast.rb', line 1567 def self.() [:def, :defs] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
1604 1605 1606 |
# File 'lib/yadriggy/ast.rb', line 1604 def accept(evaluator) evaluator.define(self) end |