attr_callback - Convenience method for providing user-definable callbacks.
The attr_callback gem lets you conveniently create user-definable callback method attributes, using a single line of code.
Example Usage
You can use attr_callback to define a callback attribute on an object:
require 'attr_callback'
class Foo
attr_callback :on_receive_message
end
f = Foo.new
# Getter and setter behave the same as they would using attr_attribute
f. = 1 #=> 1
f. #=> 1
# Passing a block to the getter makes it behave as a setter
f. { |msg| puts msg } #=> #<Proc:0x0006bfd0@(irb):1>
f. #=> #<Proc:0x0006bfd0@(irb):1>
# Invoking the callback
f..call("hello world")
Options
By default, a Mutex object will be used to guard access to the callback. This Mutex is created the first time the attribute is accessed. Use :lock=>false to disable this behaviour.
By default, a no-op Proc is returned by the getter in place of nil. Use :noop=>false to disable this behaviour.
License
Copyright © 2010 Infonium Inc.
License: See the MIT-LICENSE file.