From: David Masover Date: 2008-05-30T00:45:27+09:00 Subject: Re: Surprising Extend On Thursday 29 May 2008 10:36:27 Leslie Viljoen wrote: > > > > Can you show some real code and real error messages? Normally there > > should not be an issue with your first approach. > ----In StringExt.rb: > > module StringExt > def to_hex > unpack("C*").map{|b| b.to_s(16)}.join(" ") > end > end > > ----In use.rb: > > require 'StringExt' > > String.extend StringExt > s = "anystringwilldo" > puts s.to_hex I'm not sure, but considering that you can extend individual instances, that method has probably become a class method for String? As in, String.to_hex? But your _first_ approach should work. In StringExt.rb: class String def to_hex unpack("C*").map{|b| b.to_s(16)}.join(" ") end end In use.rb: require 'StringExt' s = 'anystringwilldo' puts s.to_hex For me, running use.rb outputs 61 6e 79 73 74 72 69 6e 67 77 69 6c 6c 64 6f tested in both Ruby 1.8 and Ruby 1.9.