Class: Opal::Nodes::Args::Parameters
- Inherits:
-
Object
- Object
- Opal::Nodes::Args::Parameters
- Defined in:
- lib/opal/nodes/args/parameters.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ Parameters
constructor
A new instance of Parameters.
- #on_arg(arg) ⇒ Object
- #on_blockarg(arg) ⇒ Object
- #on_kwarg(arg) ⇒ Object
- #on_kwnilarg(_arg) ⇒ Object
- #on_kwoptarg(arg) ⇒ Object
- #on_kwrestarg(arg) ⇒ Object
- #on_mlhs(_arg) ⇒ Object
- #on_optarg(arg) ⇒ Object
- #on_restarg(arg) ⇒ Object
- #on_shadowarg(_arg) ⇒ Object
- #to_code ⇒ Object
Constructor Details
#initialize(args) ⇒ Parameters
Returns a new instance of Parameters.
7 8 9 |
# File '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 'lib/opal/nodes/args/parameters.rb', line 19 def on_arg(arg) arg_name = arg.[:arg_name] %{['req', '#{arg_name}']} end |
#on_blockarg(arg) ⇒ Object
62 63 64 65 66 |
# File 'lib/opal/nodes/args/parameters.rb', line 62 def on_blockarg(arg) arg_name = arg.[:arg_name] arg_name = :& if arg_name == :fwd_block_arg %{['block', '#{arg_name}']} end |
#on_kwarg(arg) ⇒ Object
43 44 45 46 |
# File 'lib/opal/nodes/args/parameters.rb', line 43 def on_kwarg(arg) arg_name = arg.[:arg_name] %{['keyreq', '#{arg_name}']} end |
#on_kwnilarg(_arg) ⇒ Object
68 69 70 |
# File 'lib/opal/nodes/args/parameters.rb', line 68 def on_kwnilarg(_arg) %{['nokey']} end |
#on_kwoptarg(arg) ⇒ Object
48 49 50 51 |
# File 'lib/opal/nodes/args/parameters.rb', line 48 def on_kwoptarg(arg) arg_name = arg.[:arg_name] %{['key', '#{arg_name}']} end |
#on_kwrestarg(arg) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/opal/nodes/args/parameters.rb', line 53 def on_kwrestarg(arg) arg_name = arg.[:arg_name] if arg_name %{['keyrest', '#{arg_name}']} else %{['keyrest']} end end |
#on_mlhs(_arg) ⇒ Object
24 25 26 |
# File 'lib/opal/nodes/args/parameters.rb', line 24 def on_mlhs(_arg) %{['req']} end |
#on_optarg(arg) ⇒ Object
28 29 30 31 |
# File 'lib/opal/nodes/args/parameters.rb', line 28 def on_optarg(arg) arg_name = arg.[:arg_name] %{['opt', '#{arg_name}']} end |
#on_restarg(arg) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/opal/nodes/args/parameters.rb', line 33 def on_restarg(arg) arg_name = arg.[: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 'lib/opal/nodes/args/parameters.rb', line 72 def on_shadowarg(_arg); end |
#to_code ⇒ Object
11 12 13 14 15 16 17 |
# 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 |