Class: Opal::Nodes::Args::Parameters
- Inherits:
-
Object
- Object
- Opal::Nodes::Args::Parameters
- Defined in:
- opal/lib/opal/nodes/args/parameters.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ Parameters
constructor
A new instance of Parameters.
- #on_arg(arg_name) ⇒ Object
- #on_blockarg(arg_name) ⇒ Object
- #on_kwarg(arg_name) ⇒ Object
- #on_kwoptarg(arg_name, _default_value) ⇒ Object
- #on_kwrestarg(arg_name = nil) ⇒ Object
- #on_mlhs ⇒ Object
- #on_optarg(arg_name, _default_value) ⇒ Object
- #on_restarg(arg_name = nil) ⇒ Object
- #on_shadowarg(_arg_name) ⇒ Object
- #to_code ⇒ Object
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_mlhs ⇒ Object
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_code ⇒ Object
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 |