Created
June 26, 2012 06:01
-
-
Save lee-dohm/2993650 to your computer and use it in GitHub Desktop.
Proper way to handle path arguments in Ruby methods
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
def callee(arg) | |
path = arg.path if arg.respond_to?(:path) | |
path ||= arg.to_path if arg.respond_to?(:to_path) | |
path ||= arg.to_str if arg.respond_to?(:to_str) | |
raise "Invalid path `#{arg}`" unless path | |
# ... do something with path | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From revision-zero.org.