Created
April 20, 2015 05:28
-
-
Save acuppy/a278b8f4cb8847006084 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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