Class: Yadriggy::Def

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

Overview

Method definition or a singular method definition.

Instance Attribute Summary collapse

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 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) ⇒ Def



1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
# File 'lib/yadriggy/ast.rb', line 1513

def initialize(sexp)
  if sexp[0] == :def
    @singular = nil
    offset = 0
  else
    @singular = to_node(sexp[1])
    add_child(@singular)
    offset = 2
  end

  def_name = sexp[1 + offset]
  @name = if def_name[0] == :@op
            to_node(def_name)
          else
            to_node(has_tag?(def_name, :@ident))
          end
  add_child(@name)

  params = sexp[2 + offset]
  if !params.nil? && params[0] == :paren
    super(params[1])
  else
    super(params)
  end

  bodystmt = has_tag?(sexp[3 + offset], :bodystmt)
  @body = Exprs.make(bodystmt[1])
  @rescue = Rescue.make(bodystmt[2], bodystmt[3], bodystmt[4])
  add_child(@body)
  add_child(@rescue)
end

Instance Attribute Details

#bodyExprs|ASTnode (readonly)



1507
1508
1509
# File 'lib/yadriggy/ast.rb', line 1507

def body
  @body
end

#nameIdentifier (readonly)



1505
1506
1507
# File 'lib/yadriggy/ast.rb', line 1505

def name
  @name
end

#rescueRescue|nil (readonly)



1509
1510
1511
# File 'lib/yadriggy/ast.rb', line 1509

def rescue
  @rescue
end

#singularASTnode|nil (readonly)



1503
1504
1505
# File 'lib/yadriggy/ast.rb', line 1503

def singular
  @singular
end

Class Method Details

.tagsObject



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

def self.tags() [:def, :defs] end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.



1548
1549
1550
# File 'lib/yadriggy/ast.rb', line 1548

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