Modules and Mixins Flashcards
1
Q
Can modules be inherited? Can you create objects for the modules?
A
No, No
2
Q
What is the difference between #remove_method and #undef_method?
A
#undef_method( ) removes all methods, including the inherited ones.
#remove_method( ) removesall the methods, incase of inheritance, it leaves inherited methods alone.
3
Q
Give the purpose of using modules?
A
Modules have 2 main purposes:
providing a namespace and prevent name clashes
using the mixin facility for composition
4
Q
Explain include keyword?
A
To do mixin we use include keyword
5
Q
Difference between prepend and extend keywords?
A
prepend keyword need object creation from class when being called.
Extend keyword don’t need object when being called
module Commentable def comment puts 'I love comments!' end end
class Post extend Commentable def comment puts'I comment!' end end
Post.comment # I love comments! #if its prepend keyword you need to do
Post.new.comment