class Yadriggy::Def

Method definition or a singular method definition.

Attributes

body[R]

@return [Exprs|ASTnode] the body.

name[R]

@return [Identifier] the method name.

rescue[R]

@return [Rescue|nil] the rescue clause.

singular[R]

@return [ASTnode|nil] the object if the definition is a singular method.

Public Class Methods

new(sexp) click to toggle source
Calls superclass method Yadriggy::Parameters::new
# File lib/yadriggy/ast.rb, line 1585
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
tags() click to toggle source
# File lib/yadriggy/ast.rb, line 1583
def self.tags() [:def, :defs] end

Public Instance Methods

accept(evaluator) click to toggle source

A method for Visitor pattern. @param [Eval] evaluator the visitor of Visitor pattern. @return [void]

# File lib/yadriggy/ast.rb, line 1620
def accept(evaluator)
  evaluator.define(self)
end