Class: Opal::Rewriters::Arguments
- Inherits:
-
Object
- Object
- Opal::Rewriters::Arguments
- Defined in:
- opal/lib/opal/rewriters/arguments.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#blockarg ⇒ Object
readonly
Returns the value of attribute blockarg.
-
#kwargs ⇒ Object
readonly
Returns the value of attribute kwargs.
-
#kwnilarg ⇒ Object
readonly
Returns the value of attribute kwnilarg.
-
#kwoptargs ⇒ Object
readonly
Returns the value of attribute kwoptargs.
-
#kwrestarg ⇒ Object
readonly
Returns the value of attribute kwrestarg.
-
#optargs ⇒ Object
readonly
Returns the value of attribute optargs.
-
#postargs ⇒ Object
readonly
Returns the value of attribute postargs.
-
#restarg ⇒ Object
readonly
Returns the value of attribute restarg.
-
#shadowargs ⇒ Object
readonly
Returns the value of attribute shadowargs.
Instance Method Summary collapse
- #can_inline_kwargs? ⇒ Boolean
- #has_any_kwargs? ⇒ Boolean
- #has_post_args? ⇒ Boolean
-
#initialize(args) ⇒ Arguments
constructor
A new instance of Arguments.
Constructor Details
#initialize(args) ⇒ Arguments
Returns a new instance of Arguments.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 10 def initialize(args) @args = [] @optargs = [] @restarg = nil @postargs = [] @kwargs = [] @kwoptargs = [] @kwrestarg = nil @kwnilarg = false @shadowargs = [] @blockarg = nil args.each do |arg| case arg.type when :arg, :mlhs (@restarg || @optargs.any? ? @postargs : @args) << arg when :optarg @optargs << arg when :restarg @restarg = arg when :kwarg @kwargs << arg when :kwoptarg @kwoptargs << arg when :kwnilarg @kwnilarg = true when :kwrestarg @kwrestarg = arg when :shadowarg @shadowargs << arg when :blockarg @blockarg = arg else raise "Unsupported arg type #{arg.type}" end end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 6 def args @args end |
#blockarg ⇒ Object (readonly)
Returns the value of attribute blockarg.
6 7 8 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 6 def blockarg @blockarg end |
#kwargs ⇒ Object (readonly)
Returns the value of attribute kwargs.
6 7 8 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 6 def kwargs @kwargs end |
#kwnilarg ⇒ Object (readonly)
Returns the value of attribute kwnilarg.
6 7 8 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 6 def kwnilarg @kwnilarg end |
#kwoptargs ⇒ Object (readonly)
Returns the value of attribute kwoptargs.
6 7 8 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 6 def kwoptargs @kwoptargs end |
#kwrestarg ⇒ Object (readonly)
Returns the value of attribute kwrestarg.
6 7 8 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 6 def kwrestarg @kwrestarg end |
#optargs ⇒ Object (readonly)
Returns the value of attribute optargs.
6 7 8 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 6 def optargs @optargs end |
#postargs ⇒ Object (readonly)
Returns the value of attribute postargs.
6 7 8 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 6 def postargs @postargs end |
#restarg ⇒ Object (readonly)
Returns the value of attribute restarg.
6 7 8 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 6 def restarg @restarg end |
#shadowargs ⇒ Object (readonly)
Returns the value of attribute shadowargs.
6 7 8 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 6 def shadowargs @shadowargs end |
Instance Method Details
#can_inline_kwargs? ⇒ Boolean
56 57 58 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 56 def can_inline_kwargs? @optargs.empty? && @restarg.nil? && @postargs.empty? end |
#has_any_kwargs? ⇒ Boolean
52 53 54 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 52 def has_any_kwargs? @kwargs.any? || @kwoptargs.any? || !@kwrestarg.nil? end |
#has_post_args? ⇒ Boolean
48 49 50 |
# File 'opal/lib/opal/rewriters/arguments.rb', line 48 def has_post_args? !@restarg.nil? || @postargs.any? || (has_any_kwargs? && !can_inline_kwargs?) end |