You can shorten the provided code using a conditional operator and string interpolation. Here's the shorter version:
main.rb90 chars6 lines
In the shortened version, the return
keyword is removed from each line since the last expression evaluated in a method is automatically returned. Additionally, we can use string interpolation (#{}
) instead of explicitly converting n
to a string using n.to_s
.
Let me know if you need any further assistance!
gistlibby LogSnag