Class: Opal::Nodes::Args::Parameters

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/nodes/args/parameters.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Parameters

Returns a new instance of Parameters.


7
8
9
# File 'opal/lib/opal/nodes/args/parameters.rb', line 7

def initialize(args)
  @args = args.children
end

Instance Method Details

#on_arg(arg_name) ⇒ Object


19
20
21
# File 'opal/lib/opal/nodes/args/parameters.rb', line 19

def on_arg(arg_name)
  %{['req', '#{arg_name}']}
end

#on_blockarg(arg_name) ⇒ Object


55
56
57
# File 'opal/lib/opal/nodes/args/parameters.rb', line 55

def on_blockarg(arg_name)
  %{['block', '#{arg_name}']}
end

#on_kwarg(arg_name) ⇒ Object


39
40
41
# File 'opal/lib/opal/nodes/args/parameters.rb', line 39

def on_kwarg(arg_name)
  %{['keyreq', '#{arg_name}']}
end

#on_kwoptarg(arg_name, _default_value) ⇒ Object


43
44
45
# File 'opal/lib/opal/nodes/args/parameters.rb', line 43

def on_kwoptarg(arg_name, _default_value)
  %{['key', '#{arg_name}']}
end

#on_kwrestarg(arg_name = nil) ⇒ Object


47
48
49
50
51
52
53
# File 'opal/lib/opal/nodes/args/parameters.rb', line 47

def on_kwrestarg(arg_name = nil)
  if arg_name
    %{['keyrest', '#{arg_name}']}
  else
    %{['keyrest']}
  end
end

#on_mlhsObject


23
24
25
# File 'opal/lib/opal/nodes/args/parameters.rb', line 23

def on_mlhs(*)
  %{['req']}
end

#on_optarg(arg_name, _default_value) ⇒ Object


27
28
29
# File 'opal/lib/opal/nodes/args/parameters.rb', line 27

def on_optarg(arg_name, _default_value)
  %{['opt', '#{arg_name}']}
end

#on_restarg(arg_name = nil) ⇒ Object


31
32
33
34
35
36
37
# File 'opal/lib/opal/nodes/args/parameters.rb', line 31

def on_restarg(arg_name = nil)
  if arg_name
    %{['rest', '#{arg_name}']}
  else
    %{['rest']}
  end
end

#on_shadowarg(_arg_name) ⇒ Object


59
# File 'opal/lib/opal/nodes/args/parameters.rb', line 59

def on_shadowarg(_arg_name); end

#to_codeObject


11
12
13
14
15
16
17
# File 'opal/lib/opal/nodes/args/parameters.rb', line 11

def to_code
  stringified_parameters = @args.map do |arg|
    public_send(:"on_#{arg.type}", *arg)
  end

  "[#{stringified_parameters.compact.join(', ')}]"
end