Any ideas why IRB would be different than running the code?

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

Quoting Wayne Brisette (wbrisett@att.net):

Any ideas why IRB would differ? Is there something wrong in my code?

Must be something different in the script you use. If I execute this script:

--8<----8<----8<----8<----8<----8<----8<----8<--
class String
  def convert_base(from,to)
    self.to_i(from).to_s(to)
  end
end

ttext=10
puts("Result: #{ttext.to_s.convert_base(2,16)}")
--8<----8<----8<----8<----8<----8<----8<----8<--

I obtain

Result: 2

Carlo

ยทยทยท

Subject: Any ideas why IRB would be different than running the code?
  Date: Sat 12 Jan 13 06:24:34AM +0900

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)