class Opal::Nodes::NodeWithArgs
Constants
- Shortcut
Shortcuts for the simplest kinds of methods
Attributes
arity[RW]
original_args[R]
used_kwargs[R]
Public Class Methods
define_shortcut(name, **kwargs, &block)
click to toggle source
# File lib/opal/nodes/node_with_args/shortcuts.rb, line 20 def self.define_shortcut(name, **kwargs, &block) kwargs[:for] ||= :def @shortcuts << Shortcut.new(name, kwargs[:for], kwargs[:when], block) end
new(*)
click to toggle source
Calls superclass method
# File lib/opal/nodes/node_with_args.rb, line 14 def initialize(*) super @original_args = @sexp.meta[:original_args] @used_kwargs = [] @arity = 0 end
shortcuts_for(node_type)
click to toggle source
# File lib/opal/nodes/node_with_args/shortcuts.rb, line 25 def self.shortcuts_for(node_type) @shortcuts_for[node_type] ||= @shortcuts.select do |shortcut| [node_type, :*].include? shortcut.for end end
Public Instance Methods
arity_check_node()
click to toggle source
# File lib/opal/nodes/node_with_args.rb, line 22 def arity_check_node s(:arity_check, original_args) end
compile_arity_check()
click to toggle source
Returns code used in debug mode to check arity of method call
# File lib/opal/nodes/node_with_args.rb, line 27 def compile_arity_check push process(arity_check_node) end
compile_block_arg()
click to toggle source
# File lib/opal/nodes/node_with_args.rb, line 31 def compile_block_arg if scope.uses_block? scope.prepare_block end end
compile_body_or_shortcut()
click to toggle source
# File lib/opal/nodes/node_with_args/shortcuts.rb, line 32 def compile_body_or_shortcut # The shortcuts don't check arity. If we want to check arity, # we can't use them. return compile_body if compiler.arity_check? node_type = is_a?(DefNode) ? :def : :iter NodeWithArgs.shortcuts_for(node_type).each do |shortcut| if shortcut.match?(self) if ENV['OPAL_DEBUG_SHORTCUTS'] node_desc = node_type == :def ? "def #{mid}" : "iter" warn "* shortcut #{shortcut.name} used for #{node_desc}" end return shortcut.compile(self) end end compile_body end
parameters_code()
click to toggle source
# File lib/opal/nodes/node_with_args.rb, line 37 def parameters_code Args::Parameters.new(original_args).to_code end
simple_value?(node = stmts)
click to toggle source
# File lib/opal/nodes/node_with_args/shortcuts.rb, line 61 def simple_value?(node = stmts) %i[true false nil int float str sym].include?(node.type) end