The following code works fine:
class Float
def round
self.format.to_f
end
def format
"%.2f" % self
end
end
However, it seems bad practice to monkeypatch a class like Float because other people are doing the same thing and it causes problems.
Then I installed simplecov and the problem started: simplecov monkeypatches the same methods.
So I created a module and mixed it in to Float.
module MyModule
def round
self.format.to_f
end
def format
"%.2f" % self
end
end
Which I guess works as well. But the problem is that simplecov seems to be overwriting the mixed-in method above.
So, what is the proper way to extend built-in classes so that they do not conflict with other people's code?
Ruby 1.9.3