[include] - makes the modules methods available to the instance of a class. It takes all the methods from another module and includes them into the current module. This is a language-level thing. The include method is the primary way to "extend" classes with other modules (usually referred to as mix-ins).
module After
end
class Example
include After
end
Example.ancestors
# => [Example, After, Object, Kernel, BasicObject]
[require] - runs another file. Also tracks what you have required in the past and won't require the same file twice. For import libraries mostly.
[require_relative] - allowing to load a file that is relative to the file containing the require_relative statement. For example if you have a rspec classes in /spec directory and data for them under the spec/data directory, then you might use the line this in test case:
require_relative "data/test"
[load] - for execute code.
[extend] - will add the extended class to the ancestors of the extending classes' singleton class. Other words extend mix the module's functionality into class and makes these methods available to the class itself.
module After
def module_method
puts "Module Method invoked"
end
end
class Example
end
ex = Example.new
ex.extend After
ex.module_method
# => Module Method invoked
[super] - is used for overridden method call by the overriding method. using super will call the same method, but as defined in the superclass and give you the result.
class Animal
def move
"I can move"
end
end
class Bird
def move
super + "by flying"
end
end
puts Animal.new.move
# => I can move
puts Bird.new.move
# => I can move by flying
[prepend] - invokes Module.prepend_features on each parameter in reverse order.
module Before
end
class Example
prepend Before
end
Example.ancestors
# => [Before, Example, Object, Kernel, BasicObject]
But does this work in ruby/rails?