Created
June 23, 2010 23:11
-
-
Save lightningdb/450706 to your computer and use it in GitHub Desktop.
OptionHashExample.rb
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
# 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