Skip to content

Instantly share code, notes, and snippets.

@acuppy
Created April 20, 2015 05:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save acuppy/a278b8f4cb8847006084 to your computer and use it in GitHub Desktop.
class Sampson < Character
def when(event, &block)
@events[event] ||= []
@events[event] << block
end
def bite_thumb
call_event :bite_thumb
end
private
def events_for event
@events[event] || []
end
def call_event event
events_for(event).each(&:call)
end
end
sampson.when(:bite_thumb) do
gregory.ask "Do you bite your thumb at us, sir?"
end
sampson.bite_thumb # => Abraham asks, “Do you..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment