Skip to content

Commit

Permalink
add Zookeeper::Callback::Base.create method
Browse files Browse the repository at this point in the history
calls the block with the callback instance itself as the first first argument.

allows libraries to extend the callback with useful information and make it available to the
called-back proc.
  • Loading branch information
slyphon committed May 4, 2012
1 parent cdbe4e2 commit 134c702
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/zookeeper/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ module Callbacks
class Base
attr_reader :proc, :completed, :context

# allows for easier construction of a user callback block that will be
# called with the callback object itself as an argument.
#
# @example
#
# Base.create do |cb|
# puts "watcher callback called with argument: #{cb.inspect}"
# end
#
# "watcher callback called with argument: #<Zookeeper::Callbacks::Base:0x1018a3958 @state=3, @type=1, ...>"
#
#
def self.create
cb_inst = new { blk.call(cb_inst) }
end

def initialize
@completed = false
@proc = Proc.new do |hash|
Expand All @@ -13,7 +29,6 @@ def initialize
end

def call(*args)
# puts "call passed #{args.inspect}"
@proc.call(*args)
end

Expand Down

0 comments on commit 134c702

Please sign in to comment.