Class: Yadriggy::Lambda

Inherits:
Block show all
Defined in:
lib/yadriggy/ast.rb

Overview

A lambda expression such as ‘-> (x) + 1`.

‘lambda {|x|x+1}` is parsed as a call to `lambda` with an argument `{|x|x + 1}`. So it is an instance of Call.

Instance Attribute Summary

Attributes inherited from Block

#body, #rescue

Attributes inherited from Parameters

#block_param, #keywords, #optionals, #params, #params_after_rest, #rest_of_keywords, #rest_of_params

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Block

#initialize_vars, tags

Methods inherited from Parameters

#initialize_params

Methods included from AstHelper

#has_tag?, #to_node, #to_nodes

Methods inherited from ASTnode

#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class

Constructor Details

#initialize(sexp) ⇒ Lambda

Returns a new instance of Lambda.



1352
1353
1354
1355
1356
1357
1358
1359
# File 'lib/yadriggy/ast.rb', line 1352

def initialize(sexp)
  if sexp[1][0] == :paren
    params = sexp[1][1]
  else
    params = sexp[1]
  end
  initialize_vars(params, sexp[2])
end

Class Method Details

.tagObject



1350
# File 'lib/yadriggy/ast.rb', line 1350

def self.tag() :lambda end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.

Parameters:

  • evaluator (Eval)

    the visitor of Visitor pattern.



1364
1365
1366
# File 'lib/yadriggy/ast.rb', line 1364

def accept(evaluator)
  evaluator.lambda_expr(self)
end