Class: Opal::Rewriters::Arguments

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/rewriters/arguments.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
# File 'opal/lib/opal/rewriters/arguments.rb', line 10

def initialize(args)
  @args = []
  @optargs = []
  @restarg = nil
  @postargs = []
  @kwargs = []
  @kwoptargs = []
  @kwrestarg = nil
  @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 :kwrestarg
      @kwrestarg = arg
    when :shadowarg
      @shadowargs << arg
    when :blockarg
      @blockarg = arg
    else
      raise "Unsupported arg type #{arg.type}"
    end
  end
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



6
7
8
# File 'opal/lib/opal/rewriters/arguments.rb', line 6

def args
  @args
end

#blockargObject (readonly)

Returns the value of attribute blockarg.



6
7
8
# File 'opal/lib/opal/rewriters/arguments.rb', line 6

def blockarg
  @blockarg
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



6
7
8
# File 'opal/lib/opal/rewriters/arguments.rb', line 6

def kwargs
  @kwargs
end

#kwoptargsObject (readonly)

Returns the value of attribute kwoptargs.



6
7
8
# File 'opal/lib/opal/rewriters/arguments.rb', line 6

def kwoptargs
  @kwoptargs
end

#kwrestargObject (readonly)

Returns the value of attribute kwrestarg.



6
7
8
# File 'opal/lib/opal/rewriters/arguments.rb', line 6

def kwrestarg
  @kwrestarg
end

#optargsObject (readonly)

Returns the value of attribute optargs.



6
7
8
# File 'opal/lib/opal/rewriters/arguments.rb', line 6

def optargs
  @optargs
end

#postargsObject (readonly)

Returns the value of attribute postargs.



6
7
8
# File 'opal/lib/opal/rewriters/arguments.rb', line 6

def postargs
  @postargs
end

#restargObject (readonly)

Returns the value of attribute restarg.



6
7
8
# File 'opal/lib/opal/rewriters/arguments.rb', line 6

def restarg
  @restarg
end

#shadowargsObject (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

Returns:

  • (Boolean)


53
54
55
# File 'opal/lib/opal/rewriters/arguments.rb', line 53

def can_inline_kwargs?
  @optargs.empty? && @restarg.nil? && @postargs.empty?
end

#has_any_kwargs?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'opal/lib/opal/rewriters/arguments.rb', line 49

def has_any_kwargs?
  @kwargs.any? || @kwoptargs.any? || !@kwrestarg.nil?
end

#has_post_args?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'opal/lib/opal/rewriters/arguments.rb', line 45

def has_post_args?
  !@restarg.nil? || @postargs.any? || (has_any_kwargs? && !can_inline_kwargs?)
end