Hello, I would like to use ruby modules for the first time. I understand
theirs principle for a basic usage but get quite unsure for the present
- I want to put some code in a library (railsapp/lib) to
- lighten the controller that will use it
- test unit the code on one side, and test unit the controller on
the other side
- So, the lib is like this
- class BaseModule
- class SpecificModule < BaseModule
- The controller SomeController
- creates an instance sm = SpecificModule.new
I don’t like the idea of creating an instance - Because it seems (to me)
too much Java/C++ oriented
Instead I would like
Then, I could call doIt() from the controller
Hence, my question :
- is it ‘good design’ to use the modules like this ? May I have some
(bad) surprises later ?
- are the modules ‘motchable / stubbable’ ?
- is it different to unit test modules compared to classes ?
I did few tries with modules (see above) and I have a question more :
why did I need to use the ‘self’ keyword with self.my_stuff or
self.method_payment ? (without self. the methods are unknow under
I had a look to the rails code base and it seems that most methods
defined in modules don’t use it… In my case it seems that I should use
Any advice ?
Thank for the attention
@@attribut = “payment”
p ‘here again’
@@attribut_specific = “foo”
a = AClass.new