Class: Introspection::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/introspection/snapshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Snapshot

Returns a new instance of Snapshot.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/introspection/snapshot.rb', line 9

def initialize(object)
  @methods = (object.receivers rescue []).map do |receiver|
    [:public, :protected, :private].map do |visibility|
      query_method = "#{visibility}_instance_methods"
      receiver.send(query_method, false).map do |method|
        unbound_method = receiver.instance_method(method)
        if unbound_method.owner.equal?(receiver)
          Method.new(unbound_method, visibility)
        end
      end.compact
    end
  end.flatten
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



7
8
9
# File 'lib/introspection/snapshot.rb', line 7

def methods
  @methods
end

Instance Method Details

#changed?(other) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/introspection/snapshot.rb', line 30

def changed?(other)
  diff(other).values.flatten.any?
end

#diff(other) ⇒ Object



23
24
25
26
27
28
# File 'lib/introspection/snapshot.rb', line 23

def diff(other)
  {
    :added => other.methods - methods,
    :removed => methods - other.methods
  }
end