Skip to content

Instantly share code, notes, and snippets.

@lee-dohm
Created June 26, 2012 06:01
Show Gist options
  • Save lee-dohm/2993650 to your computer and use it in GitHub Desktop.
Save lee-dohm/2993650 to your computer and use it in GitHub Desktop.
Proper way to handle path arguments in Ruby methods
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
@lee-dohm
Copy link
Author

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