Ruby on Rails Thursday, August 29, 2013

> Please help me to understand what does mean by "If used with no
> arguments, subsequently defined methods become module functions."?

Okay got it now:-

module Party
module_function
def foo
"I am foo"
end
def bar
"I am bar"
end
end

Party.foo # => "I am foo"
Party.bar # => "I am bar"

--
Posted via http://www.ruby-forum.com/.

--
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/4325306fab9efe46f82cd965e21134ac%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

The documentation is very straight forward and the mentioned example
also cleared all the lines except the one mentioned inside **.

http://ruby-doc.org/core-2.0.0/Module.html#method-i-module_function

Creates module functions for the named methods. These functions may be
called with the module as a receiver, and also become available as
instance methods to classes that mix in the module. Module functions are
copies of the original, and so may be changed independently. The
instance-method versions are made private. *If used with no arguments,
subsequently defined methods become module functions.*


module Mod
def one
"This is one"
end
module_function :one
end
class Cls
include Mod
def call_one
one
end
end
Mod.one #=> "This is one"
c = Cls.new
c.call_one #=> "This is one"
module Mod
def one
"This is the new one"
end
end
Mod.one #=> "This is one"
c.call_one #=> "This is the new one"

Please help me to understand what does mean by "If used with no
arguments, subsequently defined methods become module functions."?

--
Posted via http://www.ruby-forum.com/.

--
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/5a19164430bc09f5e89b1766a48e5bf3%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

tamouse m. wrote in post #1119977:
> On Aug 29, 2013, at 5:33 AM, Shawn h. <lists@ruby-forum.com> wrote:
>
> Using launchd is much like using cron on linux: there is no (or barely
> any) predefined environment like you have in Terminal. Thus you have to
> provide all the information that will be needed to make sure your script
> runs correctly. This is includes running whatever is needed to set the
> right version and source of ruby for that launcher.
>
> Since OS/X ships with 1.8.7 as the system ruby, that is the one used by
> launchd. If you require a different version (and you do if you want to
> use any gems you've installed for that different version), you have to
> wrap your ruby script in something that will initialize the environment.
> I haven't tried this, but it might just be enough to add init-file
> /Users/youruser/.bash_profile to the argument list above, depending on
> how you have things configured.

Thanks! I think this is the right direction and I am gonna give it a
try. I just test adding ruby path to both /etc/launchd.conf and
/etc/paths. After rebooting, I thought it would work but not. Launchd
still does not recognize the correct ruby version. I will report once it
works.

--
Posted via http://www.ruby-forum.com/.

--
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/4ff6d7e4a42cd98e7e9bcccb51f6d3e0%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.