class Sexp

Constants

NODE_NAMES

Attributes

modified[RW]

Whether or not this sexp is a mutated/modified sexp.

modified?[RW]

Whether or not this sexp is a mutated/modified sexp.

Public Instance Methods

all_structural_subhashes() click to toggle source

Returns a list of structural hashes for all nodes (and sub-nodes) of this sexp.

# File lib/flay.rb, line 558
def all_structural_subhashes
  hashes = []
  self.deep_each do |node|
    hashes << node.structural_hash
  end
  hashes
end
code_index() click to toggle source

Return the index of the last non-code element, or nil if this sexp is not a code-bearing node.

# File lib/flay.rb, line 603
def code_index
  {
   :block  => 0,    # s(:block,                   *code)
   :class  => 2,    # s(:class,      name, super, *code)
   :module => 1,    # s(:module,     name,        *code)
   :defn   => 2,    # s(:defn,       name, args,  *code)
   :defs   => 3,    # s(:defs, recv, name, args,  *code)
   :iter   => 2,    # s(:iter, recv,       args,  *code)
  }[self.sexp_type]
end
Also aliased as: has_code?
has_code?()
Alias for: code_index
split_at(n) click to toggle source

Useful general array method that splits the array from 0..n and the rest. Returns both sections.

# File lib/flay.rb, line 595
def split_at n
  return self[0..n], self[n+1..-1]
end
split_code() click to toggle source

Split the sexp into front-matter and code-matter, returning both. See code_index.

# File lib/flay.rb, line 620
def split_code
  index = self.code_index
  self.split_at index if index
end
structural_hash() click to toggle source

Calculate the structural hash for this sexp. Cached, so don’t modify the sexp afterwards and expect it to be correct.

# File lib/flay.rb, line 550
def structural_hash
  @structural_hash ||= pure_ruby_hash
end