Any sage advice would be greatly appreciated. Full code for the exercise is as follows:
class Fraction
attr_accessor 'numerator', 'denominator'
def initialize(numerator, denominator)
@numerator = numerator
@denominator = denominator
end
def gcd(a,b)
return a if b == 0
gcd(b, a%b)
end
def lowest
lowest = gcd(@numerator, @denominator)
@numerator /= lowest
@denominator /= lowest
end
def to_f
@numerator.to_f / @denominator.to_f
end
def to_s
"#{@numerator}/#{@denominator}"
end
end
Ok gang, my turn please.
My
lowest
method is behaving oddly. When i call it separately to theinitialize
method in two steps it behaves as expected:When the methods are concatenated it seems to reverse the numerator and denominator values for some arcane reason:
Any sage advice would be greatly appreciated. Full code for the exercise is as follows: