Skip to content
loading...

re: Daily Challenge #138 - Do I get a Bonus? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Ruby: def total_salary(base_salary, getting_bonus) "$#{getting_bonus ? (base_salary * 10).to_s : base_salary.to_s}" end
 

String interpolation calls to_s by itself, no need to explicitly do it. :-)

"$#{getting_bonus ? base_salary * 10 : base_salary}"

But since multiplying by 10 is just adding a 0, you can also do this (not recommended though, more clever than useful):

"$#{base_salary}#{0 if getting_bonus}"
 

lol, haven't used Ruby in a while so I wanted to be sure (though, now that you mention it, implicitly converting to string in interpolation makes sense :)

Clever on adding a zero!

code of conduct - report abuse