I am assigning a temp password to my users.
Now I have this as code and it works:
temp_password = random_pronouncable_password
@user = User.create!(params[:user].merge(:password => temp_password, :password_confirmation => temp_password))
but I want a way to be able to do this
@user = User.create!(params[:user].merge(:password, :password_confirmation => temp_password))
Anyone know how to do something like this?
If you only have two, then just repeat them and maybe format your code to make the repeat obvious:
Anything else will just be a bunch of extra noise that serves no useful purpose. Anyone that looks at the above will immediately know what’s going on with barely a thought and that’s an indicator of good clean code.
You could probably come up with something clever using the
Hash[]constructor or possibly a Hash with a default value but that would be a waste of cleverness. Cleverness is in limited supply so you should save it for special occasions when it is really needed.