On Tue, May 22, 2012 at 12:17 PM, Jan E. <[email protected]> wrote: > I also don't think you can reassign self without digging into Ruby's > source code.
What are you guys talking about reassigning self all the time? David wants to change the class of an instance - not its identity. Even if you could reassign self inside a method all variable references still point to the same old instance self pointed to before. This clearly does not achieve the goal as stated. > My idea was to at least *fake* an object transformation by > making the nil instance a wrapper for an array: > But then I realized that nil is actually a singleton object (there's > only one nil). This somewhat makes the whole thing pointless, because > any change to a nil instance would affect all "nils". Exactly. > I don't see the point in this feature, anyway. It perhaps would make > some sense if you didn't have to set the variable in the first place but > could magically create a new array by calling the push method on a new > identifier. PHP has this, for example: > > $x[0] = "abc"; // this makes $x an array > > But when you have to write "a = nil" first, then you might as well write > "a = []" and leave out all the magic. The use case is probably rather instance variables which do not require initialization and default to nil. Still, I don't think it's needed. I believe OP hasn't got the hang of how Ruby works yet. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
