Class: Code::Node::FunctionParameter

Inherits:
Code::Node show all
Defined in:
lib/code/node/function_parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Code::Node

#evaluate, #resolve

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

#defaultObject (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

Returns:



47
48
49
# File 'lib/code/node/function_parameter.rb', line 47

def block?
  !!@block
end

#keyword?Boolean

Returns:



31
32
33
# File 'lib/code/node/function_parameter.rb', line 31

def keyword?
  !!@keyword
end

#keyword_splat?Boolean

Returns:



39
40
41
# File 'lib/code/node/function_parameter.rb', line 39

def keyword_splat?
  !!@keyword_splat
end

#nameObject



23
24
25
# File 'lib/code/node/function_parameter.rb', line 23

def name
  Object::String.new(@name)
end

#regular?Boolean

Returns:



27
28
29
# File 'lib/code/node/function_parameter.rb', line 27

def regular?
  !@keyword
end

#regular_splat?Boolean

Returns:



35
36
37
# File 'lib/code/node/function_parameter.rb', line 35

def regular_splat?
  !!@regular_splat
end

#spread?Boolean

Returns:



43
44
45
# File 'lib/code/node/function_parameter.rb', line 43

def spread?
  !!@spread
end

#to_codeObject



64
65
66
# File 'lib/code/node/function_parameter.rb', line 64

def to_code
  to_h.to_code
end

#to_hObject



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