Juanito Fatas
Juanito Fatas

Reputation: 9969

What does this extend do?

Given this example:

module A
  module B
    def foo
      puts 'foo'
    end

    extend A::B
  end
end

What does this extend A::B do?

Upvotes: 0

Views: 60

Answers (1)

user1375096
user1375096

Reputation:

It extends module A::B with itself, essentially make method foo available on module object A::B itself.

Without that line, you are not able to call A::B.foo in your code.

You may want to read more on Ruby extend aModule vs include aModule.

Upvotes: 3

Related Questions