franzejr / best-ruby

Ruby Tricks, Idiomatic Ruby, Refactoring and Best Practices
http://franzejr.github.io/best-ruby/
2.39k stars 219 forks source link

Add digits trick #78

Closed IlyaUmanets closed 6 years ago

IlyaUmanets commented 6 years ago

Changes:

MarcosX commented 6 years ago

Looks nice to me!

It may be worth creating a new example line with .join.to_i at the end (awesome_number.to_s.chars.map(&:to_i).reverse.join.to_i) just so digits are reversed and an actual number is returned. What do you think?

IlyaUmanets commented 6 years ago

@MarcosX, I'm not sure that it's a good idea, the main purpose of this trick is to get a digits from a number, no need to join them and return as a reversed number.

Thank you for your comment !

MarcosX commented 6 years ago

Ah ok, the reverse was just an example. Awesome.

MarcosX commented 6 years ago

Sorry, clicked in the wrong button. I'm okay with this changes, let's see what other have to say.

IlyaUmanets commented 6 years ago

@MarcosX, Can you merge this PR ?