Skip to content

Instantly share code, notes, and snippets.

@skiz
Created November 9, 2010 18:13
Show Gist options
  • Save skiz/669510 to your computer and use it in GitHub Desktop.
Save skiz/669510 to your computer and use it in GitHub Desktop.
Argument parsing...
Action: :new
Args: {:blah=>4}
-----
Action: nil
Args: {:blah=>3}
-----
Action: :foo
Args: {:errors=>4}
-----
Action: nil
Args: {:errors=>9}
-----
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