On Sunday 03 October 2004 05:14 pm, Florian Gross wrote:
> Giulio Piancastelli wrote:
> > Yes, but the problem is that I was able to call A3.g from outside the
> > module even if it was declared private. Why is that happening? Private
> > symbols in a module are private in respect to... what?
>
> Interesting -- this is another difference between module_function
> without arguments and extend self:
>
> module A3
>    extend self
>    def f; g; end
>    private
>    def g; "A3.g"; end
> end
>
> A3.g # raises NoMethodError: private method `g' called for A3:Module
> A3.f # => "A3.g"
>
> I think the behavior of extend self is more appropriate than the
> module_function one.

Talk about your Too Many Ways!

  module X
    extend self
    private
    # ...
  end

  module X
    module_function
    # ...
  end

  module X
    class << self
      def ameth
    end
    private
    include self
  end

  module X
    class << self
      def ameth
    end
    private
    def ameth
  end

  module X
    def self.ameth
    private
    def ameth
  end

  module X
    def X.ameth
    private
    def ameth
  end

  module X
    def X.ameth
    def ameth
    priavte :ameth
  end


T.