Hugh Sasse Staff Elec Eng wrote:
> 
> How might I add some instance variables to an existing class, such
> as String, and have them initialized properly?

I tried you example in irb, with one minor bugfix:

irb(main):001:0> class String
irb(main):002:1> attr_accessor :pos
irb(main):003:1> alias old_init initialize
irb(main):004:1> def initialize(*args)
irb(main):005:2> old_init(*args)
irb(main):006:2> @pos=0
irb(main):007:2> end
irb(main):008:1> end
nil
irb(main):009:0> t = "Example"
"Example"
irb(main):010:0> t.pos
nil
irb(main):011:0> t = String.new("Example")
"Example"
irb(main):012:0> t.pos
0


You need to prefix args with * to denote that the array is to be
expanded into an argument list. Also, the t = "Example" won't use the
initialize, you have to use String.new explicilty, which may not be what
you want.

-- 
<[ Kent Dahl ]>================<[ http://www.stud.ntnu.no/~kentda/ ]>
  )____(stud.techn.;ind.шл.data)||(softwareDeveloper.at(Trustix))_( 
 /"Opinions expressed are mine and not those of my Employer,      "\
( "the University, my girlfriend, stray cats, banana fruitflies,  " )
 \"nor the frontal lobe of my left cerebral hemisphere.           "/