On Thursday, October 7, 2004, 12:49:33 AM, Joachim wrote:

> Encouraged by your quick response, I try to explain better
> what I meant in example 2:

> class Foo
>     attr_reader ... # here I forgot :pos
>     def initialize
>         ...
>         @pos = ...
>     end
> end
> ...
> blabla = someClass.someMethod.link_to_another_class.methods_pos.oof

=>> system complains "no such method"

> Formally, the system is right: I forgot to declare the read
> access method for the variable pos.

It tells you what method is missing from what object/class.  This
should be enough for you to work out the problem.

> But:
> (1) the system should tell me which method in the above
> chain causes the problem

See above.  Is your error message different from mine?  (See IRB
transcript below.)

> (2) as a naive programmer, with a background in other languages,
> I do not think of pos as method. I think of it as variable.

The system is helping you, then, by reminding you it's a method :)
There's no such thing as direct access to instance variables in Ruby.

> Once the system does not find a method, it could check whether
> there is a local variable of same name, and then print out
> an error message like
>    "no method 'pos', no read access to local variable 'pos'".

Too much effort.  Better to just learn Ruby properly.  I'm not
suggesting Ruby couldn't be made more user-friendly, but there's no
need in this area, IMO.

Cheers,
Gavin

P.S. IRB transcript:

$ irb
irb(main):001:0> class A
irb(main):002:1>   def foo
irb(main):003:2>     b = B.new
irb(main):004:2>     b.bar
irb(main):005:2>   end
irb(main):006:1> end
=> nil
irb(main):007:0> class B
irb(main):008:1> end
=> nil
irb(main):009:0> A.new.foo
NoMethodError: undefined method `bar' for #<B:0x10272b28>
        from (irb):4:in `foo'
        from (irb):9
irb(main):010:0>