Class: Golem::Model::Callback
- Inherits:
-
Object
- Object
- Golem::Model::Callback
- Defined in:
- lib/golem/model/callback.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
Instance Method Summary collapse
- #call(obj, *args) ⇒ Object
-
#initialize(callback, options = {}) ⇒ Callback
constructor
A new instance of Callback.
- #to_s ⇒ Object
Constructor Details
#initialize(callback, options = {}) ⇒ Callback
Returns a new instance of Callback.
6 7 8 |
# File 'lib/golem/model/callback.rb', line 6 def initialize(callback, = {}) @callback = callback end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
4 5 6 |
# File 'lib/golem/model/callback.rb', line 4 def callback @callback end |
Instance Method Details
#call(obj, *args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/golem/model/callback.rb', line 10 def call(obj, *args) case @callback when Proc if @callback.arity.abs > 1 @callback.call(obj, *args) else @callback.call(obj) end else if obj.method(@callback).arity.abs > 0 obj.send(@callback, *args) else obj.send(@callback) end end end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/golem/model/callback.rb', line 27 def to_s "#{@callback.inspect}" end |