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



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

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

#on_kwarg(arg_name) ⇒ Object



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

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

#on_kwnilargObject



61
62
63
# File 'opal/lib/opal/nodes/args/parameters.rb', line 61

def on_kwnilarg
  %{['nokey']}
end

#on_kwoptarg(arg_name, _default_value) ⇒ Object



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

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

#on_kwrestarg(arg_name = nil) ⇒ Object



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

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
38
# File 'opal/lib/opal/nodes/args/parameters.rb', line 31

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

#on_shadowarg(_arg_name) ⇒ Object



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

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