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