Reputation: -1 Dishonored
- Active Members
- Active Posts:
- 182 (0.1 per day)
- 01-March 11
- Profile Views:
- Last Active:
- Sep 29 2014 07:43 PM
- Dream Kudos:
Posts I've Made
Posted 15 Sep 2014I have to use <=> & i cant use Fixnum though.
Posted 15 Sep 2014so would something like this help?
def <=>(compare) divisibleBy2(int) <=> compare.divisibleBy2(compare.int)
it's printing out 4 >10 = false when it should be true
Posted 15 Sep 2014
class Integer include Comparable attr :int def <=>(compare) divisbleBy2 <=> compare.divisibleBy2(compare.int) end def initialize(int) @int = int end def inspect @int end end def divisibleBy2(x) i = 0 while x % 2 == 0 x = x/2 i = i + 1 end return i end int1 = Integer.new(4) int2 = Integer.new(10) print(int1, " > ", int2, " = ", int1 > int2, "\n")
I feel i'm so close, yet i'm getting the error of:
undefined method 'new' for Integer:Class
Keep in mind, I have to use that Integer class & not fixnum
- Member Title:
- D.I.C Head
- Age Unknown
- Birthday Unknown
AaronHopkins hasn't added any friends yet.