How can I dynamically add a method to a Math class in Ruby on Rails?
I am trying to add the following method to a Math class in Ruby on Rails:
class Math
def self.round_with_precision(number, precision)
scalar = 10.0 ** precision
number = number * scalar
number = number.round
number = number / scalar
return number;
end
end
Then I added the following to my environment. rb:
require 'lib/math'
When I open the Rails console I get the following error: './lib/math.rb:2:TypeError Math is not a class'
I seem to be missing something very simple.
Any thoughts?
Thanks in advance for your help.
+1
source to share
3 answers