Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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