Code Monkey home page Code Monkey logo

magicarg's Introduction

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

  $$\      $$\                     $$\            $$$$$$\                      
  $$$\    $$$ |                    \__|          $$  __$$\                     
  $$$$\  $$$$ | $$$$$$\   $$$$$$\  $$\  $$$$$$$\ $$ /  $$ | $$$$$$\   $$$$$$\  
  $$\$$\$$ $$ | \____$$\ $$  __$$\ $$ |$$  _____|$$$$$$$$ |$$  __$$\ $$  __$$\ 
  $$ \$$$  $$ | $$$$$$$ |$$ /  $$ |$$ |$$ /      $$  __$$ |$$ |  \__|$$ /  $$ |
  $$ |\$  /$$ |$$  __$$ |$$ |  $$ |$$ |$$ |      $$ |  $$ |$$ |      $$ |  $$ |
  $$ | \_/ $$ |\$$$$$$$ |\$$$$$$$ |$$ |\$$$$$$$\ $$ |  $$ |$$ |      \$$$$$$$ |
  \__|     \__| \_______| \____$$ |\__| \_______|\__|  \__|\__|       \____$$ |
                         $$\   $$ |                                  $$\   $$ |
                         \$$$$$$  |                                  \$$$$$$  |
                          \______/                                    \______/ 

magicarg's People

Contributors

schneems avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.