Time Travel Toaster

Sending household appliances twirling through the 4th dimension since twenty aught five

    • Edit
    • Delete
    • Tags
    • Autopost

    Hashed method args

    Is there a reason Ruby can't work like this:

    def do_something(first_arg, second_arg)
      puts "First: #{first_arg}"
      puts "Second: #{second_arg}"
    end

    do_something(:second_arg => 'blah', :first_arg => 'yeah') =>
    First: yeah
    Second: blah

    ...while still supporting this:

    do_something('yeah', 'blah') =>
    First: yeah
    Second: blah

    It sure seems like it would be the best of both worlds.
    Instead you have to do this:
    def do_something(params)
      puts "First: #{params[:first_arg]}"
      puts "Second: #{params[:second_arg]}"
    end
    ...but that's stupid and terrible because then your method signature tells you nothing (NOTHING!) about what arguments you can give it. And that makes me sad.

    And positional parameters are a major pain in the tukhus once you have more than three or so. Does the database_mode argument go here? Or is it the address hash? Yeah, fun times.

    There's probably some reason it can't work the way I want it to.
    Tags » nerd ruby
    • 18 May 2011
    • Views
    • 0 Comments
    • Permalink
    • Favorited 0 Times
    • Tweet
    • Tweet

    Comments 0 Comments

    Leave a Comment

  • wesmorgan's Posterous

    Wes Morgan

    Contributed by Wes Morgan

  • About wesmorgan

  • Subscribe

    Subscribe to this posterous
    Unsubscribe
    Follow this posterous RSS
    You're a contributor here (Edit)
    This is your Space (Edit)
    Follow by email »
    Get the latest updates in your email box automatically.
  • Follow Me

      TwitterTwitterFacebook

Theme created for Posterous by Obox