Created
November 9, 2010 18:13
-
-
Save skiz/669510 to your computer and use it in GitHub Desktop.
Argument parsing...
This file contains 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
Action: :new | |
Args: {:blah=>4} | |
----- | |
Action: nil | |
Args: {:blah=>3} | |
----- | |
Action: :foo | |
Args: {:errors=>4} | |
----- | |
Action: nil | |
Args: {:errors=>9} | |
----- |
This file contains 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 foo(*args) | |
meth = args.shift if args[1].respond_to?(:shift) | |
meth ||= args[0].delete(:action) | |
opts = args[0] | |
puts "Action: " << meth.inspect | |
puts "Args: " << opts.inspect | |
puts "-----" | |
end | |
foo(:new, :blah => 4) | |
foo(:blah => 3) | |
foo(:action => :foo, :errors => 4) | |
foo(:errors => 9) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment