Class: Riml::DefNode
- Inherits:
-
Struct
- Object
- Struct
- Riml::DefNode
- Includes:
- FullyNameable, Indentable, Visitable, Walkable
- Defined in:
- lib/nodes.rb
Overview
Method definition.
Direct Known Subclasses
Constant Summary collapse
- SPLAT =
lambda {|arg| arg == Riml::Constants::SPLAT_LITERAL || arg[0] == "*"}
- DEFAULT_PARAMS =
lambda {|p| DefaultParamNode === p}
Constants included from Visitable
Visitable::DESCENDANT_OF_REGEX
Instance Attribute Summary collapse
-
#bang ⇒ Object
Returns the value of attribute bang.
-
#expressions ⇒ Object
Returns the value of attribute expressions.
-
#keywords ⇒ Object
Returns the value of attribute keywords.
-
#name ⇒ Object
Returns the value of attribute name.
- #original_name ⇒ Object
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#private_function ⇒ Object
Returns the value of attribute private_function.
-
#scope_modifier ⇒ Object
Returns the value of attribute scope_modifier.
-
#sid ⇒ Object
(also: #sid?)
Returns the value of attribute sid.
Attributes included from Visitable
#compiled_output, #force_newline, #parent_node, #scope
Instance Method Summary collapse
-
#argument_variable_names ⇒ Object
[“arg1”, “arg2”}.
- #autoload? ⇒ Boolean
- #children ⇒ Object
- #default_param_nodes ⇒ Object
- #defined_on_dictionary? ⇒ Boolean
-
#initialize(*args) ⇒ DefNode
constructor
A new instance of DefNode.
- #method_missing(method, *args, &blk) ⇒ Object
- #nested_function? ⇒ Boolean
- #nested_within ⇒ Object
- #shadowed_argument?(var_name) ⇒ Boolean
- #shadowed_argument_variable_names ⇒ Object
-
#splat ⇒ Object
returns the splat argument or nil.
- #super_node ⇒ Object
- #to_scope ⇒ Object
Methods included from Walkable
#child_after, #child_previous_to, #each, #index_by_children, #index_by_member, #insert_after, #insert_before, #next, #previous, #remove, #replace_with
Methods included from FullyNameable
Methods included from Indentable
Methods included from Visitable
Constructor Details
#initialize(*args) ⇒ DefNode
Returns a new instance of DefNode.
606 607 608 609 610 611 612 613 614 615 |
# File 'lib/nodes.rb', line 606 def initialize(*args) super # max number of arguments in viml if parameters.reject(&DEFAULT_PARAMS).size > 20 raise Riml::UserArgumentError, "can't have more than 20 parameters for #{full_name}" end expressions.nodes.select { |node| DefNode === node}.each do |nested_func| nested_func.nested_within.unshift(self) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
693 694 695 696 697 698 699 |
# File 'lib/nodes.rb', line 693 def method_missing(method, *args, &blk) if children.respond_to?(method) children.send(method, *args, &blk) else super end end |
Instance Attribute Details
#bang ⇒ Object
Returns the value of attribute bang
598 599 600 |
# File 'lib/nodes.rb', line 598 def bang @bang end |
#expressions ⇒ Object
Returns the value of attribute expressions
598 599 600 |
# File 'lib/nodes.rb', line 598 def expressions @expressions end |
#keywords ⇒ Object
Returns the value of attribute keywords
598 599 600 |
# File 'lib/nodes.rb', line 598 def keywords @keywords end |
#name ⇒ Object
Returns the value of attribute name
598 599 600 |
# File 'lib/nodes.rb', line 598 def name @name end |
#original_name ⇒ Object
620 621 622 |
# File 'lib/nodes.rb', line 620 def original_name @original_name ||= name end |
#parameters ⇒ Object
Returns the value of attribute parameters
598 599 600 |
# File 'lib/nodes.rb', line 598 def parameters @parameters end |
#private_function ⇒ Object
Returns the value of attribute private_function.
604 605 606 |
# File 'lib/nodes.rb', line 604 def private_function @private_function end |
#scope_modifier ⇒ Object
Returns the value of attribute scope_modifier
598 599 600 |
# File 'lib/nodes.rb', line 598 def scope_modifier @scope_modifier end |
#sid ⇒ Object Also known as: sid?
Returns the value of attribute sid
598 599 600 |
# File 'lib/nodes.rb', line 598 def sid @sid end |
Instance Method Details
#argument_variable_names ⇒ Object
[“arg1”, “arg2”}
626 627 628 |
# File 'lib/nodes.rb', line 626 def argument_variable_names parameters.reject(&SPLAT) end |
#autoload? ⇒ Boolean
663 664 665 |
# File 'lib/nodes.rb', line 663 def autoload? name.include?('#') end |
#children ⇒ Object
684 685 686 687 688 689 690 691 |
# File 'lib/nodes.rb', line 684 def children children = if sid? [sid, expressions] else [expressions] end children.concat(default_param_nodes) end |
#default_param_nodes ⇒ Object
680 681 682 |
# File 'lib/nodes.rb', line 680 def default_param_nodes parameters.select(&DEFAULT_PARAMS) end |
#defined_on_dictionary? ⇒ Boolean
659 660 661 |
# File 'lib/nodes.rb', line 659 def defined_on_dictionary? keywords.include?('dict') end |
#nested_function? ⇒ Boolean
642 643 644 |
# File 'lib/nodes.rb', line 642 def nested_function? not nested_within.empty? end |
#nested_within ⇒ Object
638 639 640 |
# File 'lib/nodes.rb', line 638 def nested_within @nested_within ||= [] end |
#shadowed_argument?(var_name) ⇒ Boolean
630 631 632 |
# File 'lib/nodes.rb', line 630 def shadowed_argument?(var_name) shadowed_argument_variable_names.include?(var_name) end |
#shadowed_argument_variable_names ⇒ Object
634 635 636 |
# File 'lib/nodes.rb', line 634 def shadowed_argument_variable_names @shadowed_argument_variable_names ||= Set.new end |
#splat ⇒ Object
returns the splat argument or nil
647 648 649 |
# File 'lib/nodes.rb', line 647 def splat parameters.detect(&SPLAT) end |
#super_node ⇒ Object
669 670 671 |
# File 'lib/nodes.rb', line 669 def super_node expressions.nodes.detect {|n| SuperNode === n} end |
#to_scope ⇒ Object
673 674 675 676 677 678 |
# File 'lib/nodes.rb', line 673 def to_scope ScopeNode.new.tap do |scope| scope.argument_variable_names += argument_variable_names scope.function = self end end |