|
|
|
|
|
by JohnBooty
998 days ago
|
|
That sounds like some malpractice. Ruby has had keyword arguments since Ruby 2.0 from 2008 and earlier code could certainly use option hashes. So I don't see a reason for any confusion there. # probably malpractice in a system where many methods
# take IDs and some take Users
def do_something_with_user(user)
end
# how hard is this? trivially easy and unambiguous.
def do_something_with_user(user_id:)
end
In the second example, you would really have to be asleep at the wheel to make a mistake like: # this is obviously wrong
do_something_with_user(user_id: User.first)
I don't see the problem. It would be nice if a compiler/IDE could catch that, but on the other hand, it just looks blatantly wrong as you type it and will certainly blow up the first time you call it. |
|