Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Make our arguments magical

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 autotest
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .autotest
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 license.txt
README.md

MagicArg

Use MagicArg to order and parse your overloaded arguments in ruby. I know you're pretty excited, keep reading it just gets better.

Example

  def build_key(*args)
    keys, options = MagicArg.parse(args, "*keys, options = {}")
  end

Pass the args you get directly to MagicArg.parse then tell it how you want your arguments returned (in this case *keys, options = {}) and MagicArg will do the rest.

This is essentially the same as defining the method build_key(*keys, options={}) (which you can't do in ruby right now).

MagicArg lets you give your consumer the interface you want.

  build_key(:put, :whatever, :you, :want, :then => "pass in a hash", :as => "options"

MagicArg also allows us to "type" our input arguments. Just put the class name in square brackets. Like this:

    foo, bar = MagicArg.parse(args, "*foo[Numeric], *bar[Symbol]")

    foo, bar = MagicArg.parse(args, "foo = {}, bar[String]")

    foo, bar = MagicArg.parse(args, "foo, bar")

    #...

This is my _why day project hope you enjoy it. No Gem cut yet, let me know if you're interested.

My Other Fun Projects

Contribution

Fork away. If you want to chat about a feature idea, or a question you can find me on the twitters @schneems. Put any major changes into feature branches. Make sure all tests stay green, and make sure your changes are covered.

licensed under MIT License Copyright (c) 2011 Schneems. See LICENSE.txt for further details.

Chunky Bacon

It's awesome

  $$\      $$\                     $$\            $$$$$$\                      
  $$$\    $$$ |                    \__|          $$  __$$\                     
  $$$$\  $$$$ | $$$$$$\   $$$$$$\  $$\  $$$$$$$\ $$ /  $$ | $$$$$$\   $$$$$$\  
  $$\$$\$$ $$ | \____$$\ $$  __$$\ $$ |$$  _____|$$$$$$$$ |$$  __$$\ $$  __$$\ 
  $$ \$$$  $$ | $$$$$$$ |$$ /  $$ |$$ |$$ /      $$  __$$ |$$ |  \__|$$ /  $$ |
  $$ |\$  /$$ |$$  __$$ |$$ |  $$ |$$ |$$ |      $$ |  $$ |$$ |      $$ |  $$ |
  $$ | \_/ $$ |\$$$$$$$ |\$$$$$$$ |$$ |\$$$$$$$\ $$ |  $$ |$$ |      \$$$$$$$ |
  \__|     \__| \_______| \____$$ |\__| \_______|\__|  \__|\__|       \____$$ |
                         $$\   $$ |                                  $$\   $$ |
                         \$$$$$$  |                                  \$$$$$$  |
                          \______/                                    \______/ 
Something went wrong with that request. Please try again.