All ruby_parser nodes in an index hash. Used by jenkins algorithm.
Whether or not this sexp is a mutated/modified sexp.
Whether or not this sexp is a mutated/modified sexp.
Returns a list of structural hashes for all nodes (and sub-nodes) of this sexp.
# File lib/flay.rb, line 548 def all_structural_subhashes hashes = [] self.deep_each do |node| hashes << node.structural_hash end hashes end
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 590 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
Useful general array method that splits the array from 0..n
and the rest. Returns both sections.
# File lib/flay.rb, line 582 def split_at n return self[0..n], self[n+1..-1] end
Split the sexp into front-matter and code-matter, returning both. See code_index.
# File lib/flay.rb, line 607 def split_code index = self.code_index self.split_at index if index end
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 540 def structural_hash @structural_hash ||= pure_ruby_hash end