Class: Fmt::Arguments
Overview
Represents arguments for a method call
Arguments are comprised of:
-
args: Array
-
kwargs: Hash[Symbol, Object]
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
: Array – positional arguments.
-
#kwargs ⇒ Object
readonly
: Hash[Symbol, Object] – keyword arguments.
Attributes inherited from Model
AST Processors collapse
-
#on_arguments(node) ⇒ Object
Processes an arguments AST node.
-
#on_float(node) ⇒ Object
Processes a float AST node.
-
#on_ident(node) ⇒ Object
Processes an identifier AST Node.
-
#on_imaginary(node) ⇒ Object
Processes an imaginary (complex) AST node.
-
#on_int(node) ⇒ Object
Processes an integer AST node.
-
#on_kw(node) ⇒ Object
Processes a keyword AST node.
-
#on_rational(node) ⇒ Object
Processes a rational AST node.
-
#on_symbeg(node) ⇒ Object
Processes a symbol start AST Node.
-
#on_symbol(node) ⇒ Object
Processes a symbol AST Node.
-
#on_tokens(node) ⇒ Object
Processes a tokens AST node.
-
#on_tstring_content(node) ⇒ Object
Processes a string AST node.
Composite Data Types (Arrays, Hashes, Sets) collapse
-
#on_label(node) ⇒ Object
Process a label (hash key) AST node.
-
#on_lbrace(node) ⇒ Object
Processes a left brace AST node.
-
#on_lbracket(node) ⇒ Object
Processes a left bracket AST node.
Instance Method Summary collapse
-
#initialize(ast) ⇒ Arguments
constructor
Constructor.
-
#to_h ⇒ Object
Hash representation of the model (required for pattern matching).
Methods inherited from Model
Methods included from Matchable
#deconstruct, #deconstruct_keys
Constructor Details
#initialize(ast) ⇒ Arguments
Constructor
15 16 17 18 19 |
# File 'lib/fmt/models/arguments.rb', line 15 def initialize(ast) @args = [] @kwargs = {} super end |
Instance Attribute Details
#args ⇒ Object (readonly)
: Array – positional arguments
21 22 23 |
# File 'lib/fmt/models/arguments.rb', line 21 def args @args end |
#kwargs ⇒ Object (readonly)
: Hash[Symbol, Object] – keyword arguments
22 23 24 |
# File 'lib/fmt/models/arguments.rb', line 22 def kwargs @kwargs end |
Instance Method Details
#on_arguments(node) ⇒ Object
Processes an arguments AST node
40 41 42 |
# File 'lib/fmt/models/arguments.rb', line 40 def on_arguments(node) process_all node.children end |
#on_float(node) ⇒ Object
Processes a float AST node
102 103 104 |
# File 'lib/fmt/models/arguments.rb', line 102 def on_float(node) assign node.children.first.to_f end |
#on_ident(node) ⇒ Object
Processes an identifier AST Node
86 87 88 89 90 |
# File 'lib/fmt/models/arguments.rb', line 86 def on_ident(node) assign node.children.first.to_sym if @next_ident_is_symbol ensure @next_ident_is_symbol = false end |
#on_imaginary(node) ⇒ Object
Processes an imaginary (complex) AST node
116 117 118 |
# File 'lib/fmt/models/arguments.rb', line 116 def on_imaginary(node) assign Complex(0, node.children.first.to_f) end |
#on_int(node) ⇒ Object
Processes an integer AST node
95 96 97 |
# File 'lib/fmt/models/arguments.rb', line 95 def on_int(node) assign node.children.first.to_i end |
#on_kw(node) ⇒ Object
Processes a keyword AST node
54 55 56 57 58 59 60 |
# File 'lib/fmt/models/arguments.rb', line 54 def on_kw(node) case node.children.first in "nil" then assign(nil) in "true" then assign(true) in "false" then assign(false) end end |
#on_label(node) ⇒ Object
Process a label (hash key) AST node
141 142 143 144 145 |
# File 'lib/fmt/models/arguments.rb', line 141 def on_label(node) label = node.children.first label = label.chop.to_sym if label.end_with?(":") assign nil, label: label # assign placeholder end |
#on_lbrace(node) ⇒ Object
Processes a left brace AST node
134 135 136 |
# File 'lib/fmt/models/arguments.rb', line 134 def on_lbrace(node) assign({}) end |
#on_lbracket(node) ⇒ Object
Processes a left bracket AST node
127 128 129 |
# File 'lib/fmt/models/arguments.rb', line 127 def on_lbracket(node) assign([]) end |
#on_rational(node) ⇒ Object
Processes a rational AST node
109 110 111 |
# File 'lib/fmt/models/arguments.rb', line 109 def on_rational(node) assign Rational(node.children.first) end |
#on_symbeg(node) ⇒ Object
Processes a symbol start AST Node
79 80 81 |
# File 'lib/fmt/models/arguments.rb', line 79 def on_symbeg(node) @next_ident_is_symbol = true end |
#on_symbol(node) ⇒ Object
Processes a symbol AST Node
72 73 74 |
# File 'lib/fmt/models/arguments.rb', line 72 def on_symbol(node) assign node.children.first.to_sym end |
#on_tokens(node) ⇒ Object
Processes a tokens AST node
47 48 49 |
# File 'lib/fmt/models/arguments.rb', line 47 def on_tokens(node) process_all node.children end |
#on_tstring_content(node) ⇒ Object
Processes a string AST node
65 66 67 |
# File 'lib/fmt/models/arguments.rb', line 65 def on_tstring_content(node) assign node.children.first end |
#to_h ⇒ Object
Hash representation of the model (required for pattern matching)
26 27 28 29 30 31 |
# File 'lib/fmt/models/arguments.rb', line 26 def to_h super.merge( args: args, kwargs: kwargs ) end |