T
Tristin Davis
[Note: parts of this message were removed to make it a legal post.]
Is there a cleaner way to implement my add_notifier method?
def add_notifier(notifier, &block)
if block_given?
@notifiers << block
else
@notifiers << notifier
end
end
def thump
raise ArgumentError, "You must add_notifier before you can notify" if
@notifiers.empty?
@notifiers.each {|n| n.call }
end
Here's how the method will be used.
hb.add_notifier nil do
puts "Notification1"
end
meth = lambda{ puts "notification2" }
hb.add_notifier(meth)
It just seems really unpretty to pass that nil when I want to pass just the
block.
Is there a cleaner way to implement my add_notifier method?
def add_notifier(notifier, &block)
if block_given?
@notifiers << block
else
@notifiers << notifier
end
end
def thump
raise ArgumentError, "You must add_notifier before you can notify" if
@notifiers.empty?
@notifiers.each {|n| n.call }
end
Here's how the method will be used.
hb.add_notifier nil do
puts "Notification1"
end
meth = lambda{ puts "notification2" }
hb.add_notifier(meth)
It just seems really unpretty to pass that nil when I want to pass just the
block.