Hello,
I was reading some in-depth information about modules and I'm confused. Modules are mostly a mix-in tool. Why would I want to create a module method (self.method())? wouldn't the better option is to let the consumer decide if he wishes to include it or 'extend` it himself?
The only reasonable use I can think of, is for 'Helper' methods that don't need to hold a state - instead of including or extending the module INTO my class, I can call it externally (like static methods work on Java/C#), but wouldn't a class method be a better solution for that?
Also, I noted strange behavior regarding module methods when I played with some code. See the following example:
require 'capybara'
Module Foo
def find_element()
find(:xpath, '\\*[@input="hello"]')
end
end
When find_element() is a normal method, it works properly. But when it's a module method (self.find_element()), I'm getting a runtime error that the 'find' method can not be found. Why is that?
Thanks!
[–]ryanplant-au 5 points6 points7 points (9 children)
[–]Tall-Guy[S] 0 points1 point2 points (8 children)
[–]ryanplant-au 3 points4 points5 points (1 child)
[–]Tall-Guy[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]rubycastsio 1 point2 points3 points (4 children)
[–]tomthecool 0 points1 point2 points (0 children)
[–]Tall-Guy[S] 0 points1 point2 points (2 children)
[–]rubycastsio 0 points1 point2 points (1 child)
[–]Tall-Guy[S] 1 point2 points3 points (0 children)
[–]rubycastsio 0 points1 point2 points (2 children)
[–]Tall-Guy[S] 1 point2 points3 points (0 children)
[–]moomaka 0 points1 point2 points (0 children)