On Fri, 31 Aug 2001, David Alan Black wrote:

> And when you do this, at the top level:
>
> >   class Foo
> >   end
> >
> >   Foo.__send__(:eval, "def bar; puts 'bar'; end")
>
> you could just as well replace the whole thing with:
>
>   def bar; puts 'bar'; end

I see, this seems to be the case.

Why, though, if I do:

  class Foo
  end

  def bar
    puts 'bar'
  end

  Foo.bar

do I get:

  NameError: private method `bar' called for Foo:Class

I've done nothing to make bar private, so why is it private?  Are all
top-level methods private?  If I do this:

  public
  def bar
    puts 'bar'
  end

  Foo.bar

Then I still get:

  NameError: private method `bar' called for Foo:Class

But if I do:

  public :bar
  Foo.bar

Then I get "bar" output.

Why is this?

Paul