|
The module_function declaration at the start of the module is a method visibility modifier, like public, private, orprotected.
It makes the method available directly on the module like a class method, and as a private instance method so the method is available un-prefixed when the module is included.- Geo.distance([51.47872, -0.610248], [51.5073346 , -0.1276831]) #=> 33.55959095208182
- include Geo
- distance([51.47872, -0.610248], [51.5073346 , -0.1276831]) #=> 33.55959095208182
- A similar effect can be achieved switching module_fuction to extend self.
- module Geo
- extend self
- ...
- end
复制代码 |
|