Skip to content

Instantly share code, notes, and snippets.

@tatey
Created January 22, 2013 05:26
Show Gist options
  • Select an option

  • Save tatey/4592323 to your computer and use it in GitHub Desktop.

Select an option

Save tatey/4592323 to your computer and use it in GitHub Desktop.
Typically we'd use hashes for this sort of things, but unlike hashes, going ChoiceTypes.doesnt_exist will raise an exception instead of returning nil.
# Known poll types. Unknown types will raise
# an exception.
#
# Poll::ChoiceTypes.time # => 'Choice::Time'
#
# @return [Struct]
ChoiceTypes = Struct.new(:time, :place, :text).new.tap do |types|
types.time = 'Choice::Time'
types.place = 'Choice::Place'
types.text = 'Choice::Text'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment