Class: CodeObject

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_diff/structure_processor.rb

Direct Known Subclasses

MetaCode, MethodCode, ModuleCode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent = nil, sexp = Sexp.new) ⇒ CodeObject

Returns a new instance of CodeObject.



7
8
9
10
11
12
13
14
15
# File 'lib/ruby_diff/structure_processor.rb', line 7

def initialize(name, parent=nil, sexp=Sexp.new)
  @name = name
  @parent = parent
  @sexp = sexp.deep_clone
  @children = []
  if parent
    parent.children << self
  end
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



4
5
6
# File 'lib/ruby_diff/structure_processor.rb', line 4

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/ruby_diff/structure_processor.rb', line 2

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



3
4
5
# File 'lib/ruby_diff/structure_processor.rb', line 3

def parent
  @parent
end

#sexpObject (readonly)

Returns the value of attribute sexp.



5
6
7
# File 'lib/ruby_diff/structure_processor.rb', line 5

def sexp
  @sexp
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
# File 'lib/ruby_diff/structure_processor.rb', line 31

def ==(other)
  return false unless other.class == self.class
  (other.signature == self.signature) and (other.sexp == self.sexp)
end

#child_signaturesObject



21
22
23
24
25
# File 'lib/ruby_diff/structure_processor.rb', line 21

def child_signatures
  h = {}
  self.children.each{|c| h[c.signature] = c}
  h
end

#signatureObject



17
18
19
# File 'lib/ruby_diff/structure_processor.rb', line 17

def signature
  self.name
end

#to_sObject



27
28
29
# File 'lib/ruby_diff/structure_processor.rb', line 27

def to_s
  signature
end