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) ⇒ Object



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

def on_arg(arg)
  arg_name = arg.meta[:arg_name]
  %{['req', '#{arg_name}']}
end

#on_blockarg(arg) ⇒ Object



62
63
64
65
66
# File 'opal/lib/opal/nodes/args/parameters.rb', line 62

def on_blockarg(arg)
  arg_name = arg.meta[:arg_name]
  arg_name = :& if arg_name == :fwd_block_arg
  %{['block', '#{arg_name}']}
end

#on_kwarg(arg) ⇒ Object



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

def on_kwarg(arg)
  arg_name = arg.meta[:arg_name]
  %{['keyreq', '#{arg_name}']}
end

#on_kwnilarg(_arg) ⇒ Object



68
69
70
# File 'opal/lib/opal/nodes/args/parameters.rb', line 68

def on_kwnilarg(_arg)
  %{['nokey']}
end

#on_kwoptarg(arg) ⇒ Object



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

def on_kwoptarg(arg)
  arg_name = arg.meta[:arg_name]
  %{['key', '#{arg_name}']}
end

#on_kwrestarg(arg) ⇒ Object



53
54
55
56
57
58
59
60
# File 'opal/lib/opal/nodes/args/parameters.rb', line 53

def on_kwrestarg(arg)
  arg_name = arg.meta[:arg_name]
  if arg_name
    %{['keyrest', '#{arg_name}']}
  else
    %{['keyrest']}
  end
end

#on_mlhs(_arg) ⇒ Object



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

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

#on_optarg(arg) ⇒ Object



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

def on_optarg(arg)
  arg_name = arg.meta[:arg_name]
  %{['opt', '#{arg_name}']}
end

#on_restarg(arg) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'opal/lib/opal/nodes/args/parameters.rb', line 33

def on_restarg(arg)
  arg_name = arg.meta[:arg_name]
  if arg_name
    arg_name = :* if arg_name == :fwd_rest_arg
    %{['rest', '#{arg_name}']}
  else
    %{['rest']}
  end
end

#on_shadowarg(_arg) ⇒ Object



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

def on_shadowarg(_arg); 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