Parent

Class/Module Index [+]

Quicksearch

Sexp

Sexp changes from ruby_parser and some changes for caching hash value and tracking 'original' line number of a Sexp.

Constants

ASSIGNMENT_BOOL

Attributes

paren[R]

Public Instance Methods

arglist() click to toggle source

Returns arglist for method call. This differs from Sexp#args, as Sexp#args does not return a 'real' Sexp (it does not have a node type) but Sexp#arglist returns a s(:arglist, ...)

s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2)))
                                             ^------------ arglist ------------^
# File lib/ruby_parser/bm_sexp.rb, line 186
def arglist
  expect :call, :attrasgn, :super, :zsuper

  case self.node_type
  when :call, :attrasgn
    self[3..-1].unshift :arglist
  when :super, :zsuper
    if self[1]
      self[1..-1].unshift :arglist
    else
      Sexp.new(:arglist)
    end
  end
end
arglist=(exp) click to toggle source

Sets the arglist in a method call.

# File lib/ruby_parser/bm_sexp.rb, line 163
def arglist= exp
  expect :call, :attrasgn
  start_index = 3

  if exp.is_a? Sexp and exp.node_type == :arglist
    exp = exp[1..-1]
  end

  exp.each_with_index do |e, i|
    self[start_index + i] = e
  end
end
args() click to toggle source

Returns arguments of a method call. This will be an 'untyped' Sexp.

s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2)))
                                                         ^--------args--------^
# File lib/ruby_parser/bm_sexp.rb, line 205
def args
  expect :call, :attrasgn, :super, :zsuper

  case self.node_type
  when :call, :attrasgn
    if self[3]
      self[3..-1]
    else
      Sexp.new
    end
  when :super, :zsuper
    if self[1]
      self[1..-1]
    else
      Sexp.new
    end
  end
end
block(delete = nil) click to toggle source

Returns block of a call with a block. Could be a single expression or a block:

s(:iter,
 s(:call, nil, :x, s(:arglist)),
  s(:lasgn, :y),
   s(:block, s(:lvar, :y), s(:call, nil, :z, s(:arglist))))
   ^-------------------- block --------------------------^
# File lib/ruby_parser/bm_sexp.rb, line 350
def block delete = nil
  unless delete.nil? #this is from RubyParser
    return find_node :block, delete
  end

  expect :iter, :call_with_block, :scope, :resbody

  case self.node_type
  when :iter, :call_with_block
    self[3]
  when :scope
    self[1]
  when :resbody
    #This is for Ruby2Ruby ONLY
    find_node :block
  end
end
block_args() click to toggle source

Returns parameters for a block

s(:iter,
 s(:call, nil, :x, s(:arglist)),
  s(:lasgn, :y), <- block_args
   s(:call, nil, :p, s(:arglist, s(:lvar, :y))))
# File lib/ruby_parser/bm_sexp.rb, line 374
def block_args
  expect :iter, :call_with_block
  self[2]
end
block_call() click to toggle source

Method call associated with a block:

s(:iter,
 s(:call, nil, :x, s(:arglist)), <- block_call
  s(:lasgn, :y),
   s(:block, s(:lvar, :y), s(:call, nil, :z, s(:arglist))))
# File lib/ruby_parser/bm_sexp.rb, line 337
def block_call
  expect :iter, :call_with_block
  self[1]
end
body() click to toggle source

Returns body of a method definition, class, or module. This will be an untyped Sexp containing a list of Sexps from the body.

# File lib/ruby_parser/bm_sexp.rb, line 462
def body
  expect :defn, :defs, :methdef, :selfdef, :class, :module

  case self.node_type
  when :defn, :methdef, :class
    self[3..-1]
  when :defs, :selfdef
    self[4..-1]
  when :module
    self[2..-1]
  end
end
body=(exp) click to toggle source

Sets body, which is now a complicated process because the body is no longer a separate Sexp, but just a list of Sexps.

# File lib/ruby_parser/bm_sexp.rb, line 439
def body= exp
  expect :defn, :defs, :methdef, :selfdef, :class, :module

  case self.node_type
  when :defn, :methdef, :class
    index = 3
  when :defs, :selfdef
    index = 4
  when :module
    index = 2
  end

  self.slice!(index..-1) #Remove old body

  #Insert new body
  exp.each do |e|
    self[index] = e
    index += 1
  end
end
body_list() click to toggle source

Like Sexp#body, except the returned Sexp is of type :rlist instead of untyped.

# File lib/ruby_parser/bm_sexp.rb, line 477
def body_list
  self.body.unshift :rlist
end
call() click to toggle source

Returns the call Sexp in a result returned from FindCall

# File lib/ruby_parser/bm_sexp.rb, line 499
def call
  expect :result

  self.last
end
class_name() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 486
def class_name
  expect :class, :module
  self[1]
end
Also aliased as: module_name
comments=(*args) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 109
def comments= *args
  @my_hash_value = nil
  old_comments_set(*args)
end
Also aliased as: old_comments_set
compact() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 89
def compact
  @my_hash_value = nil
  old_compact
end
Also aliased as: old_compact
condition() click to toggle source

Returns condition of an if expression:

s(:if,
 s(:lvar, :condition), <-- condition
 s(:lvar, :then_val),
 s(:lvar, :else_val)))
# File lib/ruby_parser/bm_sexp.rb, line 303
def condition
  expect :if
  self[1]
end
each_arg(replace = false) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 224
def each_arg replace = false
  expect :call, :attrasgn, :super, :zsuper
  range = nil

  case self.node_type
  when :call, :attrasgn
    if self[3]
      range = (3...self.length)
    end
  when :super, :zsuper
    if self[1]
      range = (1...self.length)
    end
  end

  if range
    range.each do |i|
      res = yield self[i]
      self[i] = res if replace
    end
  end

  self
end
each_arg!(&block) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 249
def each_arg! &block
  self.each_arg true, &block
end
each_sexp() click to toggle source

Iterates over the Sexps in an Sexp, skipping values that are not an Sexp.

# File lib/ruby_parser/bm_sexp.rb, line 116
def each_sexp
  self.each do |e|
    yield e if Sexp === e
  end
end
else_clause() click to toggle source

Returns 'else' clause of an if expression:

s(:if,
 s(:lvar, :condition),
 s(:lvar, :then_val),
 s(:lvar, :else_val)))
 ^---else caluse---^
# File lib/ruby_parser/bm_sexp.rb, line 326
def else_clause
  expect :if
  self[3]
end
expect(*types) click to toggle source

Raise a WrongSexpError if the nodes type does not match one of the expected types.

# File lib/ruby_parser/bm_sexp.rb, line 124
def expect *types
  unless types.include? self.node_type
    raise WrongSexpError, "Expected #{types.join ' or '} but given #{self.inspect}", caller[1..-1]
  end
end
file=(*args) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 84
def file= *args
  @my_hash_value = nil
  old_file_set(*args)
end
Also aliased as: old_file_set
find_and_replace_all(*args) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 94
def find_and_replace_all *args
  @my_hash_value = nil
  old_fara(*args)
end
Also aliased as: old_fara
find_node(*args) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 99
def find_node *args
  @my_hash_value = nil
  old_find_node(*args)
end
Also aliased as: old_find_node
first_arg() click to toggle source

Returns first argument of a method call.

# File lib/ruby_parser/bm_sexp.rb, line 254
def first_arg
  expect :call, :attrasgn
  self[3]
end
first_arg=(exp) click to toggle source

Sets first argument of a method call.

# File lib/ruby_parser/bm_sexp.rb, line 260
def first_arg= exp
  expect :call, :attrasgn
  self[3] = exp
end
first_param() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 379
def first_param
  expect :args
  self[1]
end
formal_args() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 426
def formal_args
  expect :defn, :defs, :methdef, :selfdef

  case self.node_type
  when :defn, :methdef
    self[2]
  when :defs, :selfdef
    self[3]
  end
end
hash() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 66
def hash
  #There still seems to be some instances in which the hash of the
  #Sexp changes, but I have not found what method call is doing it.
  #Of course, Sexp is subclasses from Array, so who knows what might
  #be going on.
  @my_hash_value ||= super
end
last_arg() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 287
def last_arg
  expect :call, :attrasgn

  if self[3]
    self[-1]
  else
    nil
  end
end
lhs() click to toggle source

Returns the left hand side of assignment or boolean:

s(:lasgn, :x, s(:lit, 1))
           ^--lhs
# File lib/ruby_parser/bm_sexp.rb, line 388
def lhs
  expect *ASSIGNMENT_BOOL
  self[1]
end
lhs=(exp) click to toggle source

Sets the left hand side of assignment or boolean.

# File lib/ruby_parser/bm_sexp.rb, line 394
def lhs= exp
  expect *ASSIGNMENT_BOOL
  self[1] = exp
end
line(num = nil) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 74
def line num = nil
  @my_hash_value = nil if num
  old_line(num)
end
Also aliased as: old_line
line=(*args) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 79
def line= *args
  @my_hash_value = nil
  old_line_set(*args)
end
Also aliased as: old_line_set
method() click to toggle source

Returns method of a method call:

s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))

^- method
# File lib/ruby_parser/bm_sexp.rb, line 149
def method
  expect :call, :attrasgn, :super, :zsuper, :result

  case self.node_type
  when :call, :attrasgn
    self[2]
  when :super, :zsuper
    :super
  when :result
    self.last
  end
end
method_missing(name, *args) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 8
def method_missing name, *args
  #Brakeman does not use this functionality,
  #so overriding it to raise a NoMethodError.
  #
  #The original functionality calls find_node and optionally
  #deletes the node if found.
  raise NoMethodError.new("No method '#{name}' for Sexp", name, args)
end
method_name() click to toggle source

Returns name of method being defined in a method definition.

# File lib/ruby_parser/bm_sexp.rb, line 415
def method_name
  expect :defn, :defs, :methdef, :selfdef

  case self.node_type
  when :defn, :methdef
    self[1]
  when :defs, :selfdef
    self[2]
  end
end
module() click to toggle source

Returns the module the call is inside

# File lib/ruby_parser/bm_sexp.rb, line 506
def module
  expect :result

  self[1]
end
module_name() click to toggle source
Alias for: class_name
node_type=(type) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 40
def node_type= type
  self[0] = type
end
old_comments_set(*args) click to toggle source
Alias for: comments=
old_compact() click to toggle source
Alias for: compact
old_fara(*args) click to toggle source
old_file_set(*args) click to toggle source
Alias for: file=
old_find_node(*args) click to toggle source
Alias for: find_node
old_line(num = nil) click to toggle source
Alias for: line
old_line_set(*args) click to toggle source
Alias for: line=
original_line(line = nil) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 56
def original_line line = nil
  if line
    @my_hash_value = nil
    @original_line = line
    self
  else
    @original_line ||= nil
  end
end
paren=(arg) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 104
def paren= arg
  @my_hash_value = nil
  @paren = arg
end
parent_name() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 493
def parent_name
  expect :class
  self[2]
end
render_type() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 481
def render_type
  expect :render
  self[1]
end
result_class() click to toggle source

Return the class the call is inside

# File lib/ruby_parser/bm_sexp.rb, line 513
def result_class
  expect :result

  self[2]
end
rhs() click to toggle source

Returns right side (value) of assignment or boolean:

s(:lasgn, :x, s(:lit, 1))
              ^--rhs---^
# File lib/ruby_parser/bm_sexp.rb, line 403
def rhs
  expect *ASSIGNMENT_BOOL
  self[2]
end
rhs=(exp) click to toggle source

Sets the right hand side of assignment or boolean.

# File lib/ruby_parser/bm_sexp.rb, line 409
def rhs= exp
  expect *ASSIGNMENT_BOOL
  self[2] = exp
end
second() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 32
def second
  self[1]
end
second_arg() click to toggle source

Returns second argument of a method call.

# File lib/ruby_parser/bm_sexp.rb, line 266
def second_arg
  expect :call, :attrasgn
  self[4]
end
second_arg=(exp) click to toggle source

Sets second argument of a method call.

# File lib/ruby_parser/bm_sexp.rb, line 272
def second_arg= exp
  expect :call, :attrasgn
  self[4] = exp
end
set_args(*exp) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 176
def set_args *exp
  self.arglist = exp
end
target() click to toggle source

Returns target of a method call:

s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))

^-----------target-----------^
# File lib/ruby_parser/bm_sexp.rb, line 134
def target
  expect :call, :attrasgn
  self[1]
end
target=(exp) click to toggle source

Sets the target of a method call:

# File lib/ruby_parser/bm_sexp.rb, line 140
def target= exp
  expect :call, :attrasgn
  self[1] = exp
end
then_clause() click to toggle source

Returns 'then' clause of an if expression:

s(:if,
 s(:lvar, :condition),
 s(:lvar, :then_val), <-- then clause
 s(:lvar, :else_val)))
# File lib/ruby_parser/bm_sexp.rb, line 314
def then_clause
  expect :if
  self[2]
end
third_arg() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 277
def third_arg
  expect :call, :attrasgn
  self[5]
end
third_arg=(exp) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 282
def third_arg= exp
  expect :call, :attrasgn
  self[5] = exp
end
to_sym() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 36
def to_sym
  self.value.to_sym
end
value() click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 21
def value
  raise WrongSexpError, "Sexp#value called on multi-item Sexp", caller[1..-1] if size > 2
  last
end
value=(exp) click to toggle source
# File lib/ruby_parser/bm_sexp.rb, line 26
def value= exp
  raise WrongSexpError, "Sexp#value= called on multi-item Sexp", caller[1..-1] if size > 2
  @my_hash_value = nil
  self[1] = exp
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.