nil is very rarely the value I want my instance variable to have. I’m
not sure that I’ve gained anything except complexity by having attr_xxx
intialize instance variables. It’s an interesting idea, though.
Paul
···
On Thu, Feb 20, 2003 at 07:13:05AM +0900, ahoward wrote:
ahhh. you are correct there. i still maintain, however, that requiring
forward intialization on instance variables, due to ruby’s dual
delclare/define syntax, is more than requiring initialization (lhs expr), but
is also requiring forward declaration/definition. why not simply make
attr_xxx :foo
initialize @foo to nil? or is that what you were suggesting?
Hi,
Foo = Class.new(super) {
def foo
…
end
…
}
But then its name is fixed in the code as ‘Foo’? What if the name I want to
give to the class is in the string object ‘klassname’? (Actually probably
not important, as I’d be better to create an anonymous class and hold onto a
reference to it rather than use it by name, but I’d still like to know 
Object.const_set(klassname, Class.new(super){…})
Is the above example for Ruby 1.8+? I can’t get it to work under 1.6.8, and
the Pickaxe doesn’t say anything about Class.new taking a block argument:
Yes.
matz.
···
In message “Re: How to test for existence of instance variable?” on 03/02/20, Brian Candler B.Candler@pobox.com writes: