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.