David A. Black wrote: >Simon Strandgaard wrote: >> Still... I propose that 'class<<self' should invoke #extended or some sort >> of suitable replacement, so that initialization can take place. >> What do you think ? >> >> Should it be named #extended ? or have another name? > >I don't think there needs to be such a thing. (If there is, it >definitely shouldn't have the word "extend" in it, since that could >cause confusion with the current concept of extending an object, as >described wrongly by me and correctly by Kent.) As Nobu pointed out >in another thread, you can just do: > > class << obj > puts "Executing a puts statement...." > # ... > end > > and the code will execute. Sorry.. this doesn't work in the following example. I have tried with instance_eval, but no luck either. server> ruby a.rb a.rb:9: undefined local variable or method `init' for #<Class:#<String:0x810aa08>> (NameError) server> expand -t2 a.rb obj = "text" class << obj def init @str = "hello" end def hello puts @str end init end obj.hello server> -- Simon Strandgaard