Class: RubyMVC::Toolkit::ObserverReference

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_mvc/toolkit/notification.rb

Overview

This class allows obsevers to register a single block rather than implementing public observer methods (which can get messy and unnecessarily pollute the public API of the class)

Each registered block will be called with the following arguments:

1) The notification name (or the method name to be called) 2) The sender of the notification 3) The notification parameters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(observer, &block) ⇒ ObserverReference

Returns a new instance of ObserverReference.



46
47
48
49
# File 'lib/ruby_mvc/toolkit/notification.rb', line 46

def initialize(observer, &block)
  @observer = observer
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/ruby_mvc/toolkit/notification.rb', line 51

def method_missing(method, *args, &block)
  if @observer.respond_to? method
    @observer.send(method, *args, &block)
  elsif !@block.nil?
    @block.call(method, *args)
  else
    super
  end
end

Instance Attribute Details

#observerObject (readonly)

Returns the value of attribute observer.



44
45
46
# File 'lib/ruby_mvc/toolkit/notification.rb', line 44

def observer
  @observer
end