irb(main):001:0> class Foo; end
=> nil
irb(main):002:0> foo = Foo.new
=> #Foo:0x400d7528
irb(main):003:0> foo.instance_variable_set :bar, 15
NameError: bar' is not an instance variable name from (irb):3:ininstance_variable_set’
from (irb):3
On Tuesday, April 8, 2003, at 03:12 PM, Chris Pine wrote:
Hello,
Is this how this is supposed to work?
irb(main):001:0> class Foo; end
=> nil
irb(main):002:0> foo = Foo.new
=> #Foo:0x400d7528
irb(main):003:0> foo.instance_variable_set :bar, 15
NameError: bar' is not an instance variable name from (irb):3:in instance_variable_set’
from (irb):3
I didn’t realize that the `@’ is just part of the name… thought it was
some sort of syntax identifier.
Perhaps the error message could be a little clearer, though. I thought it
meant, “I can’t set that variable because it doesn’t exist,” hence my
confusion.
On Tuesday, April 8, 2003, at 03:12 PM, Chris Pine wrote:
Hello,
Is this how this is supposed to work?
irb(main):001:0> class Foo; end
=> nil
irb(main):002:0> foo = Foo.new
=> #Foo:0x400d7528
irb(main):003:0> foo.instance_variable_set :bar, 15
NameError: bar' is not an instance variable name from (irb):3:in instance_variable_set’
from (irb):3
But the instance variable would be called :@bar
It is a bit confusing, though - if you made an attr_accessor for @bar,
you refer to it as :bar, not :@bar :
In message “Re: instance_variable_set question” on 03/04/09, “Chris Pine” nemo@hellotree.com writes:
Perhaps the error message could be a little clearer, though. I thought it
meant, “I can’t set that variable because it doesn’t exist,” hence my
confusion.
In message “Re: instance_variable_set question” on 03/04/09, Phil Tomson ptkwt@shell1.aracnet.com writes:
It is a bit confusing, though - if you made an attr_accessor for @bar,
you refer to it as :bar, not :@bar :
You’re specifying attribute names (i.e. exporting method names), which
does not contain “@” in them, not instance variable names.
attr_accessor defines methods that use instance variables which names
are “@”+attribute-name.
Perhaps the error message could be a little clearer, though. I thought it
meant, “I can’t set that variable because it doesn’t exist,” hence my
confusion.
Any concrete suggestion, please?
matz.
Perhaps a small note in README.EXT?
···
In message “Re: instance_variable_set question” > on 03/04/09, “Chris Pine” nemo@hellotree.com writes:
----- Original Message -----
From: “Yukihiro Matsumoto” matz@ruby-lang.org
Sure.
The error was:
NameError: `bar’ is not an instance variable name
Instead, perhaps:
NameError: instance variable names must begin with `@’.
NameError: bar' is not an instance variable name; did you mean@bar’?
I prefer the second; I really like it when the interpreter makes
suggestions. When it makes a good suggestion, it’s wonderful. When it
makes a bad suggestion, it makes it much easier to see what is confusing the
interpreter.
My basic confusion was that I thought the error was saying “bar' doesn't happen to be an instance variable name in this particular object" rather than "bar’ is not allowable as an instance variable name, not now, not
ever.”
At Wed, 9 Apr 2003 11:13:35 +0900, Yukihiro Matsumoto wrote:
Perhaps the error message could be a little clearer, though. I thought it
meant, “I can’t set that variable because it doesn’t exist,” hence my
confusion.
Any concrete suggestion, please?
What about these?
foo' is not proper for an instance variable name. bar’ is not recognized as an instance variable name.
Perhaps the error message could be a little clearer, though. I
thought it
meant, “I can’t set that variable because it doesn’t exist,” hence my
confusion.
Any concrete suggestion, please?
matz.
Perhaps a small note in README.EXT?
Whoops. Apparently the top thread was referring to “pure ruby”, though
it was something that also comes up when writing extensions.
Mea culpa.
···
In message “Re: instance_variable_set question” >> on 03/04/09, “Chris Pine” nemo@hellotree.com writes:
NameError: instance variable names must begin with `@'.
NameError: bar' is not an instance variable name; did you mean @bar’?
They are precise in your case, but:
$ ruby -e ‘instance_variable_set :“@bar…”, 15’
-e:1:in instance_variable_set': @bar…’ is not an instance variable name (NameError)
from -e:1
My basic confusion was that I thought the error was saying “bar' doesn't happen to be an instance variable name in this particular object" rather than "bar’ is not allowable as an instance variable name, not now, not
ever.”
Isn’t it fair enough?
NameError: `bar’ is not allowable as an instance variable name.
···
At Wed, 9 Apr 2003 14:01:59 +0900, Chris Pine wrote:
My basic confusion was that I thought the error was saying “bar' doesn't happen to be an instance variable name in this particular object" rather than "bar’ is not allowable as an instance variable name, not now, not
ever.”
Personally, the top one is my favorite. The second one is weird english,
and the last one has the same problem as the current error message.
NameError: `bar’ is not allowable as an instance variable name.