0.0
No commit activity in last 3 years
No release in over 3 years
The attr_callback gem lets you create user-definable callback method attributes conveniently.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

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.on_receive_message = 1                           #=> 1
f.on_receive_message                               #=> 1

# Passing a block to the getter makes it behave as a setter
f.on_receive_message { |msg| puts msg }            #=> #<Proc:0x0006bfd0@(irb):1>
f.on_receive_message                               #=> #<Proc:0x0006bfd0@(irb):1>

# Invoking the callback
f.on_receive_message.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.