defbob(type: 'water',money: '0.0')exact={'americano'=>'2.20','latte'=>'2.30','flat white'=>'2.40','filter'=>'3.50'}[type.to_s.downcase]==money{true=>"Here is your #{type.to_s}, have a nice day!",false=>'Sorry, exact change only, try again tomorrow!'}[exact]end
Outputs:
putsbob()# Sorry, exact change only, try again tomorrow!putsbob(type: 'Latte',money: '2.50')# Sorry, exact change only, try again tomorrow!putsbob(type: 'Latte',money: '2.30')# Here is your Latte, have a nice day!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here you have a version using only ruby hashes:
Outputs: