Modules and Mixins Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Can modules be inherited? Can you create objects for the modules?

A

No, No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain include keyword?

A

To do mixin we use include keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly