Class: Yoda::Parsing::NodeObjects::ArgsNode
- Inherits:
-
Object
- Object
- Yoda::Parsing::NodeObjects::ArgsNode
- Defined in:
- lib/yoda/parsing/node_objects/args_node.rb
Instance Attribute Summary collapse
- #node ⇒ Object readonly
Instance Method Summary collapse
- #block_parameter_node ⇒ ::AST::Node?
-
#initialize(node) ⇒ ArgsNode
constructor
A new instance of ArgsNode.
- #keyword_parameter_nodes ⇒ Array<::AST::Node>
- #keyword_rest_parameter_node ⇒ ::AST::Node?
- #parameter ⇒ Model::Parameters::Multiple
- #parameter_nodes ⇒ Array<::AST::Node>
- #post_parameter_nodes ⇒ Array<::AST::Node>
- #rest_parameter_node ⇒ ::AST::Node?
Constructor Details
#initialize(node) ⇒ ArgsNode
Returns a new instance of ArgsNode.
10 11 12 13 |
# File 'lib/yoda/parsing/node_objects/args_node.rb', line 10 def initialize(node) fail ArgumentError, node unless node.is_a?(::AST::Node) && node.type == :args @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
7 8 9 |
# File 'lib/yoda/parsing/node_objects/args_node.rb', line 7 def node @node end |
Instance Method Details
#block_parameter_node ⇒ ::AST::Node?
53 54 55 |
# File 'lib/yoda/parsing/node_objects/args_node.rb', line 53 def block_parameter_node @block_parameter_node ||= node.children.find { |arg_node| arg_node.type == :blockarg } end |
#keyword_parameter_nodes ⇒ Array<::AST::Node>
43 44 45 |
# File 'lib/yoda/parsing/node_objects/args_node.rb', line 43 def keyword_parameter_nodes @keyword_parameter_nodes ||= node.children.select { |arg_node| %i(kwarg kwoptarg).include?(arg_node.type) } end |
#keyword_rest_parameter_node ⇒ ::AST::Node?
48 49 50 |
# File 'lib/yoda/parsing/node_objects/args_node.rb', line 48 def keyword_rest_parameter_node @keyword_rest_parameter_node ||= node.children.find { |arg_node| arg_node.type == :kwrestarg } end |
#parameter ⇒ Model::Parameters::Multiple
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/yoda/parsing/node_objects/args_node.rb', line 16 def parameter Model::Parameters::Multiple.new( parameters: parameter_nodes.map(&method(:parse_arg_node)), rest_parameter: rest_parameter_node && parse_single_arg_node(rest_parameter_node), post_parameters: post_parameter_nodes.map(&method(:parse_arg_node)), keyword_parameters: keyword_parameter_nodes.map { |arg_node| Model::Parameters::Named.new(arg_node.children.first) }, keyword_rest_parameter: keyword_rest_parameter_node && parse_single_arg_node(keyword_rest_parameter_node), block_parameter: block_parameter_node && parse_single_arg_node(block_parameter_node), ) end |
#parameter_nodes ⇒ Array<::AST::Node>
28 29 30 |
# File 'lib/yoda/parsing/node_objects/args_node.rb', line 28 def parameter_nodes @parameter_nodes ||= node.children.take_while { |arg_node| %i(arg optarg mlhs).include?(arg_node.type) } end |
#post_parameter_nodes ⇒ Array<::AST::Node>
38 39 40 |
# File 'lib/yoda/parsing/node_objects/args_node.rb', line 38 def post_parameter_nodes @post_parameter_nodes ||= node.children.drop_while { |arg_node| %i(arg optarg mlhs).include?(arg_node.type) }.select { |arg_node| %i(arg optarg mlhs).include?(arg_node.type) } end |
#rest_parameter_node ⇒ ::AST::Node?
33 34 35 |
# File 'lib/yoda/parsing/node_objects/args_node.rb', line 33 def rest_parameter_node @rest_parameter_node ||= node.children.find { |arg_node| arg_node.type == :restarg } end |