My Wrong Understanding
Correct Understand:
"extend" adds methods from a module into a class as class methods.
"include" adds methods from a module into a class as instance methods.
It is quite easy to demonstrate this actually.
module SomeModule
def hi
puts "hello"
end
end
class ExtendSample
extend SomeModule
end
ExtendSample.hi
class IncludeSample
include SomeModule
end
IncludeSample.new.hi
No comments:
Post a Comment