class Opal::Nodes::NodeWithArgs
def self.define_shortcut(name, **kwargs, &block)
def self.define_shortcut(name, **kwargs, &block) kwargs[:for] ||= :def @shortcuts << Shortcut.new(name, kwargs[:for], kwargs[:when], block) end
def self.shortcuts_for(node_type)
def self.shortcuts_for(node_type) @shortcuts_for[node_type] ||= @shortcuts.select do |shortcut| [node_type, :*].include? shortcut.for end end
def arity_check_node
def arity_check_node s(:arity_check, original_args) end
def compile_arity_check
def compile_arity_check push process(arity_check_node) end
def compile_block_arg
def compile_block_arg if scope.uses_block? scope.prepare_block end end
def compile_body_or_shortcut
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
def initialize(*)
def initialize(*) super @original_args = @sexp.meta[:original_args] @used_kwargs = [] @arity = 0 end
def parameters_code
def parameters_code Args::Parameters.new(original_args).to_code end
def simple_value?(node = stmts)
def simple_value?(node = stmts) %i[true false nil int float str sym].include?(node.type) end