On 9/9/07, 7stud -- <dolgun / excite.com> wrote:
> James Hunt wrote:
> > On 9/9/07, 7stud -- <dolgun / excite.com> wrote:
> >> class MyClass
> >> (NoMethodError)
> >>
> >> So, I'm not seeing any difference.
> >> --
> >> Posted via http://www.ruby-forum.com/.
> >>
> >>
> >
> > If you look at my code, the MyClass definition creates an instance
> > method called hello that calls the private greet method.  In the
> > Explicit example, greet just doesn't exist in MyExplicitClass after
> > the mixin...
>
> As far as I can tell, your private hello method is irrelevant since you
> never call the hello method:
>
If you look back at the original code posting, there were two test
sets:  The first one (with MyModule) called MyClass.new.hello, whereas
the second one (with MyExplicitModule) called MyClass.new.greet.
Perhaps a bit confusing on my part - I apologize.

MyClass#hello was a public method calling MyClass#greet (a private
method) that was mixed in via the include of MyModule.

> > MyExplicitModule.greet
> > MyExplicitClass.new.greet
Again, this is the second test set, not the first.  My apologies for
the confusion.

>
> If I add the hello method to my last example that uses module_function,
> I get the same output:
>
> module MyModule
>     def greet
>         puts "hello"
>     end
>
>     module_function :greet
> end
>
> class MyClass
>     include MyModule
>
>     def hello
>         greet
>     end
> end
>
> MyModule.greet
> MyClass.new.greet
>
> --output:--
> hello
> r1test.rb:18: private method `greet' called for #<MyClass:0x25350>
> (NoMethodError)

Because the last two lines should be:
MyModule.greet
MyClass.new.hello

That being said, I think Logan offered a much better explanation.  +1 Logan

-- 
James