I have a routine I use for converting hex, decimal, and binary values
between
each.
1.9.3-p362 :001 > class String
1.9.3-p362 :002?> def convert_base(from, to)
1.9.3-p362 :003?> self.to_i(from).to_s(to)
1.9.3-p362 :004?> end
1.9.3-p362 :005?> end
=> nil
1.9.3-p362 :017 > ttext = 10
=> 10
1.9.3-p362 :018 > ttext.to_s.convert_base(2, 16)
=> “2”
So this binary value (10) produces 2, the correct hex value.
However, when I use the same exact code in my script, I’m not seeing 2,
I’m
seeing 10.
I used RubyMine to step through the code and I see it return 10 from
convert_base.
Any ideas why IRB would differ? Is there something wrong in my code?
Wayne