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

S

S. Robert James

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
 
P

Patrick Hurley

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
 
S

S. Robert James

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top