class Opal::Nodes::Args::ExtractPostOptarg

This node is responsible for extracting a single optional post-argument

args_to_keep is the number of required post-arguments

def m(a = 1, b, c, d); end

becomes something like:

if post_args.length > 3
  a = post_args[0]
  post_args = post_args[1..-1]
end

Public Instance Methods

compile() click to toggle source
# File lib/opal/nodes/args/extract_post_optarg.rb, line 24
def compile
  add_temp name

  line "if ($post_args.length > #{args_to_keep}) #{name} = $post_args.shift();"

  return if default_value.children[1] == :undefined

  push "if (#{name} == null) #{name} = ", expr(default_value)
end