Class: Code::Node::FunctionParameter
- Inherits:
-
Code::Node
- Object
- Code::Node
- Code::Node::FunctionParameter
- Defined in:
- lib/code/node/function_parameter.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
Instance Method Summary collapse
- #block? ⇒ Boolean
-
#initialize(parsed) ⇒ FunctionParameter
constructor
A new instance of FunctionParameter.
- #keyword? ⇒ Boolean
- #keyword_splat? ⇒ Boolean
- #name ⇒ Object
- #regular? ⇒ Boolean
- #regular_splat? ⇒ Boolean
- #spread? ⇒ Boolean
- #to_code ⇒ Object
- #to_h ⇒ Object
Methods inherited from Code::Node
Constructor Details
#initialize(parsed) ⇒ FunctionParameter
Returns a new instance of FunctionParameter.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/code/node/function_parameter.rb', line 8 def initialize(parsed) return if parsed.blank? @name = parsed.delete(:name).presence || parsed[:regular_splat].presence || parsed[:keyword_splat].presence || parsed[:spread].presence || parsed[:block].presence @keyword = parsed.delete(:keyword).present? @regular_splat = parsed.delete(:regular_splat).present? @keyword_splat = parsed.delete(:keyword_splat).present? @spread = parsed.delete(:spread).present? @block = parsed.delete(:block).present? @default = Code.new(parsed.delete(:default)) if parsed.key?(:default) end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/code/node/function_parameter.rb', line 6 def default @default end |
Instance Method Details
#block? ⇒ Boolean
47 48 49 |
# File 'lib/code/node/function_parameter.rb', line 47 def block? !!@block end |
#keyword? ⇒ Boolean
31 32 33 |
# File 'lib/code/node/function_parameter.rb', line 31 def keyword? !!@keyword end |
#keyword_splat? ⇒ Boolean
39 40 41 |
# File 'lib/code/node/function_parameter.rb', line 39 def keyword_splat? !!@keyword_splat end |
#name ⇒ Object
23 24 25 |
# File 'lib/code/node/function_parameter.rb', line 23 def name Object::String.new(@name) end |
#regular? ⇒ Boolean
27 28 29 |
# File 'lib/code/node/function_parameter.rb', line 27 def regular? !@keyword end |
#regular_splat? ⇒ Boolean
35 36 37 |
# File 'lib/code/node/function_parameter.rb', line 35 def regular_splat? !!@regular_splat end |
#spread? ⇒ Boolean
43 44 45 |
# File 'lib/code/node/function_parameter.rb', line 43 def spread? !!@spread end |
#to_code ⇒ Object
64 65 66 |
# File 'lib/code/node/function_parameter.rb', line 64 def to_code to_h.to_code end |
#to_h ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/code/node/function_parameter.rb', line 51 def to_h { name: name, regular?: regular?, keyword?: keyword?, regular_splat?: regular_splat?, keyword_splat?: keyword_splat?, spread?: spread?, block?: block?, default: default } end |