Code completion for Ruby - Net Beans, RDT, and more

Discussion in 'Ruby' started by S. Robert James, Mar 22, 2007.

  1. Code completion for Ruby is on its way. I'm concerned that the
    recently popular style of using hashes to fake named params will keep
    us in the dark, though.

    And anyway, Ruby wants to get named params. How about this: declare
    the method explicitly:

    def parse(filename, char = nil, conn = nil, another_param = nil)

    and have the interpreter allow the style, by converting a final hash
    to params if and only if all of the keys match the arg names.

    So:

    parse('readme.txt', :char => 'a', :another_param => true)
    becomes
    parse('readme.txt', a, nil, true)

    whereas
    parse('readme.txt', :bad_param => 'b')
    would still be
    parse('readme.txt', {:bad_param => 'b'})
    and it would be up to the parse method to handle as it normally does.

    This would allow:
    * real named params
    * more explicit method definitions
    * code completion
    * preserve the current style
     
    S. Robert James, Mar 22, 2007
    #1
    1. Advertising

  2. On 3/22/07, S. Robert James <> wrote:
    > Code completion for Ruby is on its way. I'm concerned that the
    > recently popular style of using hashes to fake named params will keep
    > us in the dark, though.
    >
    > And anyway, Ruby wants to get named params. How about this: declare
    > the method explicitly:
    >
    > def parse(filename, char = nil, conn = nil, another_param = nil)
    >
    > and have the interpreter allow the style, by converting a final hash
    > to params if and only if all of the keys match the arg names.
    >
    > So:
    >
    > parse('readme.txt', :char => 'a', :another_param => true)
    > becomes
    > parse('readme.txt', a, nil, true)
    >
    > whereas
    > parse('readme.txt', :bad_param => 'b')
    > would still be
    > parse('readme.txt', {:bad_param => 'b'})
    > and it would be up to the parse method to handle as it normally does.
    >
    > This would allow:
    > * real named params
    > * more explicit method definitions
    > * code completion
    > * preserve the current style
    >
    >
    >


    Named parameters is in the ToDo file on 1.9 distribution:

    * named arguments like foo(nation:="german") or foo(nation: "german").


    so you may get what you want
    pth
     
    Patrick Hurley, Mar 22, 2007
    #2
    1. Advertising

  3. Right - I should clarify - my goal is to allow easy migration of all
    of the current libs that use option hashes.

    With the syntax I'm suggesting, library owners could change their
    method definitions, and not break older code.


    On Mar 22, 5:58 pm, "Patrick Hurley" <> wrote:
    > Named parameters is in the ToDo file on 1.9 distribution:
    >
    > * named arguments like foo(nation:="german") or foo(nation: "german").
    >
    > so you may get what you want
    > pth
    > On 3/22/07, S. Robert James <> wrote:
    >
    >
    >
    > > Code completion for Ruby is on its way. I'm concerned that the
    > > recently popular style of using hashes to fake named params will keep
    > > us in the dark, though.

    >
    > > And anyway, Ruby wants to get named params. How about this: declare
    > > the method explicitly:

    >
    > > def parse(filename, char = nil, conn = nil, another_param = nil)

    >
    > > and have the interpreter allow the style, by converting a final hash
    > > to params if and only if all of the keys match the arg names.

    >
    > > So:

    >
    > > parse('readme.txt', :char => 'a', :another_param => true)
    > > becomes
    > > parse('readme.txt', a, nil, true)

    >
    > > whereas
    > > parse('readme.txt', :bad_param => 'b')
    > > would still be
    > > parse('readme.txt', {:bad_param => 'b'})
    > > and it would be up to the parse method to handle as it normally does.

    >
    > > This would allow:
    > > * real named params
    > > * more explicit method definitions
    > > * code completion
    > > * preserve the current style

    >
     
    S. Robert James, Mar 22, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Torsten Schmeissel
    Replies:
    0
    Views:
    424
    Torsten Schmeissel
    Apr 29, 2005
  2. ziggs
    Replies:
    2
    Views:
    189
    Henry Robinson
    Apr 21, 2004
  3. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    221
    Jeff Wood
    Sep 29, 2005
  4. rubynuby
    Replies:
    4
    Views:
    197
    zdennis
    Nov 28, 2005
  5. Andrey Platov
    Replies:
    0
    Views:
    158
    Andrey Platov
    Apr 1, 2007
Loading...

Share This Page