I\'m trying to use Ruby modules (mixins).
I have test.rb:
#!/usr/bin/env ruby
require_relative \'lib/mymodule\'
class MyApp
include MyModule
sel
class MyApp
class << self
include MyModule
end
self.hallo
end
is the same as
class MyApp
extend MyModule
self.hallo
end
extends just opens the class object and include the module methods. "hallo" becomes a class object aka. static method of class MyApp.
So "include" inject the methods to the instances of the receiver, in your case being "self" NOT to the object itself. "extend" inject the methods to the receiver in your case being "self".
self.include MyModule // inject the methods into the instances of self
self.extend MyModule // inject the methods into object self
At class level "self" will point to your class object which is MyApp.
Also remember that "include" and "extend" are just methods defined in module.rb. "include" is a class object method (static-method) and "extend" is an instance method.