Ohhh... indeed I have tried using irb. Weird!

./alex
--
.w( the_mindstorm )p.


On 6/13/06, Alexandru Popescu <the.mindstorm.mailinglist / gmail.com> wrote:
> Using both 1.8.2 and 1.8.4: no... the method foo is invoked.
>
> ./alex
> --
> .w( the_mindstorm )p.
>
>
>
>
> On 6/13/06, Joel VanderWerf <vjoel / path.berkeley.edu> wrote:
> > Mark Volkmann wrote:
> > > I understand that methods defined at the top-level, not in any class,
> > > become methods of the class Object. Pickaxe 2 says in its discussion
> > > of the top-level environment (page 293 in my paper copy) "we're
> > > actually creating (private) instance methods for class Object". I
> > > think the "(private)" part is wrong because I can invoke top-level
> > > methods using a receiver, which I shouldn't be able to do for private
> > > methods.
> > >
> > > Here's an example.
> > >
> > > def foo; puts 'in foo'; end
> > > class Bar; end
> > > bar = Bar.new
> > > bar.foo
> > >
> > > Am I misunderstanding this?
> > >
> >
> > Don't you get an error when you call bar.foo?
> >
> > $ ruby -e "
> > def foo; puts 'in foo'; end
> > class Bar; end
> > bar = Bar.new
> > bar.foo
> > "
> > -e:5: private method `foo' called for #<Bar:0xb7dcccec> (NoMethodError)
> >
> > --
> >       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
> >
> >
> >
>