J
Jp Hastings-spital
Maybe I haven't wrapped my head around OOP in the way I should have, can
anyone explain to me why I can't do this?:
--
class Percentage < Float
def to_s(decimalplaces = 0)
(((self * 10**(decimalplaces+2)).round)/10**decimalplaces).to_s+"%"
end
end
puts Percentage.new(0.5)
--
I just get the following error:
NoMethodError: undefined method ‘new’ for Percentage:Class
I hope its obvious what I'm trying to do, let me know if there's a way
to achieve this that I'm missing!
Thanks in advance
anyone explain to me why I can't do this?:
--
class Percentage < Float
def to_s(decimalplaces = 0)
(((self * 10**(decimalplaces+2)).round)/10**decimalplaces).to_s+"%"
end
end
puts Percentage.new(0.5)
--
I just get the following error:
NoMethodError: undefined method ‘new’ for Percentage:Class
I hope its obvious what I'm trying to do, let me know if there's a way
to achieve this that I'm missing!
Thanks in advance