Skip to content

Instantly share code, notes, and snippets.

@lightningdb
Created June 23, 2010 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lightningdb/450706 to your computer and use it in GitHub Desktop.
Save lightningdb/450706 to your computer and use it in GitHub Desktop.
OptionHashExample.rb
# A method signature such as:
def blah(file, underscore_to_hyphen=true)
# will be called like so:
blah(file, true)
# where true could also be false
# this is a code smell, since it is impossible to tell
# from the call what the boolean does
# in Ruby, the convention is to use options hashes to
# 'name' method params, as follows:
def blah(file, options={})
underscore_to_hyphen = options[:underscore_to_hyphen]
# with this method signature, the method is called as follows:
blah(file, :underscore_to_hyphen => true)
# now it is clear from the method call
# what the boolean refers to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment