Class: VER::WidgetEvent
- Inherits:
- BasicObject
- Defined in:
- lib/ver/widget_event.rb
Overview
This class acts as a proxy for the widget. it forwards all methods, except for [event], which points to the event currently invoked.
This is done to allow methods operating on the widget to obtain information about the event, so they can act intelligently.
The usage of [method_missing] might make it a bit slower right after startup, but should be next to no difference to a direct reference of widget as we dynamically define the methods handled.
Due to the dynamic nature of ruby, what widget is underneath will not make any difference, and WidgetEvent will be more or less invisible outside of backtraces.
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#widget ⇒ Object
readonly
Returns the value of attribute widget.
Instance Method Summary collapse
-
#initialize(widget, event) ⇒ WidgetEvent
constructor
A new instance of WidgetEvent.
- #inspect ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(method) ⇒ Boolean
- #send(method, *args, &block) ⇒ Object
Constructor Details
#initialize(widget, event) ⇒ WidgetEvent
Returns a new instance of WidgetEvent.
19 20 21 |
# File 'lib/ver/widget_event.rb', line 19 def initialize(, event) @widget, @event = , event end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ver/widget_event.rb', line 27 def method_missing(method, *args, &block) if method =~ /=/ ::VER::WidgetEvent.class_eval(<<-RUBY, __FILE__, __LINE__) def #{method}(arg) @widget.#{method} arg end RUBY else ::VER::WidgetEvent.class_eval(<<-RUBY, __FILE__, __LINE__) def #{method}(*args, &block) @widget.#{method}(*args, &block) end RUBY end @widget.send(method, *args, &block) end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
17 18 19 |
# File 'lib/ver/widget_event.rb', line 17 def event @event end |
#widget ⇒ Object (readonly)
Returns the value of attribute widget.
17 18 19 |
# File 'lib/ver/widget_event.rb', line 17 def @widget end |
Instance Method Details
#inspect ⇒ Object
49 50 51 |
# File 'lib/ver/widget_event.rb', line 49 def inspect "#<VER::WidgetEvent widget=%p event=%p>" % [@widget, @event] end |
#respond_to?(method) ⇒ Boolean
23 24 25 |
# File 'lib/ver/widget_event.rb', line 23 def respond_to?(method) method.to_sym == :event || @widget.respond_to?(method) end |
#send(method, *args, &block) ⇒ Object
45 46 47 |
# File 'lib/ver/widget_event.rb', line 45 def send(method, *args, &block) @widget.send(method, *args, &block) end |