Forum: Ruby Style question for packaging methods into a namespace

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2017-04-25 10:29
From what I can see, the following three ways are equivalent, when we
want to group methods into a namespace such that they can be called as,
i.e., NS.foo or NS.bar (or, equivalently, using a Module to get the
effect of a singleton class):

(1) Explicit self

    module NS
      def self.foo; ....; end
      def self.bar; ....; end
    end

(2) Implicit self

    module NS
      extend self;
      def foo; ....; end
      def bar; ....; end
    end

(3) module_function

    module NS
      def foo; ....; end
      def bar; ....; end
      module_function :foo, :bar
    end

So far, I have nearly always used variant (2), because it seemed to me
the easiest. Any opinions on this, i.e. whether maybe (1) or (3) would
be a better way to do it?

Ronald
This topic is locked and can not be replied to.