Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created December 23, 2011 23:23
Show Gist options
  • Save leejarvis/62513bf48b7fff7b1e2e to your computer and use it in GitHub Desktop.
Save leejarvis/62513bf48b7fff7b1e2e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def register(object = nil, &block)
obj = block_given? ? block : object
obj.call if obj.respond_to?(:call)
end
class MyClass
def call
puts "three"
end
end
register proc { puts "one" }
register { puts "two" }
register MyClass.new
register "foo" # fail silently
# one
# two
# three
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment