I tried creating a module in /lib/my_foo/foo_bar.rb called module
MyFoo::FooBar.  Inside that module I defined a method getFoo().  I
modified application.rb and added the line config.autoload_paths +=
%W(#{Rails.root}/lib).

When I tried to access MyFoo::FooBar.getFoo() in my controller I got the
following error:
undefined method `getFoo' for MyFoo::FooBar:Module

I realized that I didn't make getFoo a class method so I tried changing
the method definition to MyFoo::FooBar.getFoo(), but then I got the
following error:

syntax error, unexpected '.', expecting '\n' or ';'
    def MyFoo::FooBar.getFoo()

I then tried changing the method definition to self.getFoo() and
everything works fine.  I also tried moving foo_bar.rb directly into
/lib, changed the module name to FooBar and the method definition to
FooBar.getFoo() and that also worked.  My question is why?  I assume I
just don't have the correct syntax for specifying the module name when
it's in one or more sub-directories off of /lib instead of directly in
/lib, but I can't figure out what the correct syntax should be.

I'm fine with using "self", but I'd like to understand what I'm doing
wrong.

-- 
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to