Class: MethodObserver

Inherits:
Object
  • 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.



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

def result
  @result
end

#targetObject (readonly)

Returns the value of attribute target.



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

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



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

def observe(target)
  raise ObserverCannotObserveTwiceError if @target

  @target = target
  make_observable(target)
end