[Rails] This modules thing somehow really does not work for me, please help.
Hey,
thank you in advance for reading this post. I struggle with
modularization / packaging / name spacing (however you want to call
it) via ruby modules. I have the feeling that somehow rails is
responsible for the problems I am facing. I hope, you can help me.
Here's an example to demonstrate more exactly what I mean:
module Storage
module Administration
def self.do_something()
# .. omitted
end
end
end
This does sometimes work under the rails console (development mode),
most of the time I get:
ruby-1.9.2-p290 :004 > Storage::Administration.do_something()
NoMethodError: undefined method `do_something' for
Storage::Administration:Module
This one here works more often (but not always):
module Storage::Administration
def self.do_something()
# .. omitted
end
end
What's about the constant resolution operator (::)? As far as I know
it is only allowed to reference constants (like module or class
names), but not directly in definitions (module X::Y::Z).
As I know it from pure ruby the first example should do it. You just
nest the modules as you need and simply reopen a module if you want to
extend it.
So, the contents of my ruby files used for this example:
"storage.rb" file (in a directory called "storage"):
module Storage
end
And my "administration.rb" (in a subdirectory of "storage" called
"administration"):
module Storage
module Administration
# .. omitted
end
end
OR (as I also tried)
module Storage::Administration
# .. omitted
end
What am I doing wrong? Why can't rails (console, runner, etc.) access
my static method _all the time_?
Thank you very much for any suggestions!
ms
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home