Ruby on Rails Thursday, August 29, 2013

On Aug 29, 2013, at 2:16 PM, Love U Ruby <lists@ruby-forum.com> wrote:
> Please help me to understand what does mean by "If used with no
> arguments, subsequently defined methods become module functions."?

That means you can use it as a means of saying "All the methods defined below are module functions":


Module M

def foo
end

module_function

def bar
end

def baz
end

end

and so you can then call M.bar and M.baz, but not M.foo.

This is identical to:

Module M
def foo;end
def bar;end
def baz;end
module_function :bar, :baz
end

It is *also* identical to:

Module M
def foo;end
def self.bar; end
def self.baz; end
end


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/58BD364C-563B-439E-AA7B-D4068A1B521C%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment