Is it possible in Ruby to create a module which will have one method (for example: a math method for computing lcd), and include that method to Integer class, so that I can do after something like this
6.lcd(3)
If it's possible, how can I include it?
You can simply do something like this, without using a module:
class Fixnum
def lcd(nr)
self * nr
end
end
puts 3.lcd(2) # -> 6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With