Skip to content

Instantly share code, notes, and snippets.

@fj
Created May 23, 2012 22:57
Show Gist options
  • Save fj/2778358 to your computer and use it in GitHub Desktop.
Save fj/2778358 to your computer and use it in GitHub Desktop.
Spot the subtle error
class CountrySearch
# Return the phone country code matching a particular
# two-letter country code (e.g. 'FR' will get France's
# country code, which is 33).
def self.country_code_for_alpha2(code)
return ArgumentError unless code =~ /^..$/
return nil unless c = Country[code]
c.country_code
end
end
@btaitelb
Copy link

You probably want to raise ArgumentError

@fj
Copy link
Author

fj commented May 24, 2012

@btaitelb: bingo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment