Class: Yadriggy::Lambda

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

Overview

A lambda expression such as -> (x) {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.



1422
1423
1424
1425
1426
1427
1428
1429
# File 'lib/yadriggy/ast.rb', line 1422

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



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

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.



1434
1435
1436
# File 'lib/yadriggy/ast.rb', line 1434

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