Class: MethodObserver

Inherits:
Object show all
Defined in:
lib/method_observer.rb

Defined Under Namespace

Classes: ObserverCannotObserveTwiceError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resultObject

Returns the value of attribute result.



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

def result
  @result
end

#targetObject (readonly)

Returns the value of attribute target.



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

def target
  @target
end

Class Method Details

.instancesObject



18
19
20
# File 'lib/method_observer.rb', line 18

def self.instances
  @instances ||= {}
end

.new(*args) ⇒ Object



22
23
24
25
26
# File 'lib/method_observer.rb', line 22

def self.new(*args)
  o = super
  instances[o.object_id] = o
  o
end

Instance Method Details

#observe(target) ⇒ Object



12
13
14
15
16
# File 'lib/method_observer.rb', line 12

def observe(target)
  raise ObserverCannotObserveTwiceError if @target
  @target = target
  make_observable(target)
end