class Opal::Nodes::Args::Parameters

Public Class Methods

new(args) click to toggle source
# File lib/opal/nodes/args/parameters.rb, line 7
def initialize(args)
  @args = args.children
end

Public Instance Methods

on_arg(arg) click to toggle source
# File 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) click to toggle source
# File 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) click to toggle source
# File 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) click to toggle source
# File lib/opal/nodes/args/parameters.rb, line 68
def on_kwnilarg(_arg)
  %{['nokey']}
end
on_kwoptarg(arg) click to toggle source
# File 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) click to toggle source
# File 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) click to toggle source
# File lib/opal/nodes/args/parameters.rb, line 24
def on_mlhs(_arg)
  %{['req']}
end
on_optarg(arg) click to toggle source
# File 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) click to toggle source
# File 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) click to toggle source
# File lib/opal/nodes/args/parameters.rb, line 72
def on_shadowarg(_arg); end
to_code() click to toggle source
# File 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