class ObservableObject::Wrapper

Public Class Methods

new(obj,methods,deep,notifier=nil,&event) click to toggle source
# File lib/observable_object.rb, line 86
def initialize(obj,methods,deep,notifier=nil,&event)
  @deep = deep
  @notifier = notifier || Notifier.new(self,&event)
  @watcher = Watcher::create(obj,methods)
  @obj = @deep ? DeepWrap::map_obj(obj,@notifier) : obj
end

Public Instance Methods

!() click to toggle source
# File lib/observable_object.rb, line 102
def !
  !@obj
end
!=(other) click to toggle source
# File lib/observable_object.rb, line 99
def !=(other)
  @obj != other
end
==(other) click to toggle source
# File lib/observable_object.rb, line 93
def ==(other)
  @obj == other
end
eql?(other) click to toggle source
# File lib/observable_object.rb, line 96
def eql?(other)
  @obj.eql?(other)
end
method_missing(mname,*args,&block) click to toggle source
# File lib/observable_object.rb, line 114
def method_missing(mname,*args,&block)
  @watcher.remember { @obj }

  res = @obj.__send__(mname,*args,&block)
  chain = @obj.equal?(res)                # did the wrapped object return itself from this method?
  
  if @watcher.is_state_changing(@obj,mname)
    @obj = DeepWrap::map_obj(@obj,@notifier) if @deep # remap; some nested objects could have changed
    @notifier.call 
  end
  
  chain ? self : res                      # for chaining return self when the underlying object returns self
end
respond_to?(mname) click to toggle source
# File lib/observable_object.rb, line 111
def respond_to?(mname)
  @obj.respond_to?(mname)
end