From: "T. Onoma" Date: 2004-08-23T02:16:54+09:00 Subject: Re: Callback for instance var creation? On Sunday 22 August 2004 06:40 am, Robert Klemme wrote: > > are "instantiated" upon use and set to nil. > > No, they are instantiated on first assignment: > >> class Foo;end Oh! I didn't realize b/c if you assign from one that doesn't exist, it returns nil. irb(main):001:0> x=@x => nil irb(main):002:0> p x nil => nil > > I would like to set this to > > something else dependent on the name of the variable. > Which problem are you trying to solve? Usually attribute accessors can do > what you want. Actually, its esoteric. I've been thinking about methods as 1st class objects. At one point I have suggested that constants be used. See: http://www.rubygarden.org/ruby?FirstClassMethods But constants are class-level while methods are actually instance level (strangely enough). So I thought if they were instance level perhaps an instance variable would be better. Using the capitalization idea from before, something like: def ameth(x) puts x end p @Ameth # => # So I was trying to auto-assign @Ameth. > Other than that if you need to intercept all variable settings a modified > Hash might be better for managing your instance vars: Perhaps something like that would be better. I'll give it some thought. Thanks! T.