Extensions to Integer in Ruby on Rails

preview_player
Показать описание
When building apps with Rails, did you ever have to use modulus operator to check if a number is multiple of another number?
For example:
if number % 3 == 0
 puts "number is multiple of 3"
end
This ain't the Rails way 🙃
A cooler approach would be to use:
 puts "number is multiple of 3"
end
What if you need the ordinal representation of an integer, for instance: Turn 2 into 2nd.
You can use the ordinalize method to achieve that.
Did you know you can also get Time objects from integers using the from_now and ago methods?
Let's say,

💻 Follow for more programming videos 💻

#ruby #programming #computerscience #webdevelopment #softwareengineer #rubyonrails #rubydeveloper #rubyonrailsdeveloper
Рекомендации по теме