From: Simon Strandgaard Date: 2004-03-05T00:29:53+09:00 Subject: Re: class< neither included nor extended works On Fri, 05 Mar 2004 00:08:45 +0900, nobu.nokad wrote: > At Thu, 4 Mar 2004 22:59:45 +0900, > Simon Strandgaard wrote in [ruby-talk:94219]: >> I would like to execute some code at the point >> when the 'class<> >> But I cannot figure out how ? > > I don't know what you really want... > >> txt = "text" >> class << txt > puts "like this?" Yes.. however if I invoke 'install' instead of above 'puts', then b.rb:3: undefined local variable or method `install' for #> (NameError) server> ruby b.rb nil b.rb:9: warning: instance variable @state not initialized change state old= new=true true true server> cat b.rb obj = "im just some random object" class << obj #install # why doesn't this work? def install puts "install" @state = false end attr_reader :state def change_state(state) puts "change state old=#{@state} new=#{state}" @state = state end end p obj.state p obj.change_state(true) p obj.state server> -- Simon Strandgaard