2

I have following code:

module CarHelper
  def call_helpline
    puts "Calling helpline..."
  end
end

class Car
  extend CarHelper
end

class Truck
  class << self
    include CarHelper
  end
end

# Test code
Car.call_helpline
Truck.call_helpline

In fact both 2 lines of test codes works. So is there any difference between the way I use 'extend' and 'include' (inside a singleton class of self)?

Trung Lê
  • 5,188
  • 5
  • 27
  • 26
  • 2
    See the interesting discussion about [What is the difference between include and extend in Ruby?](http://stackoverflow.com/questions/156362/what-is-the-difference-between-include-and-extend-in-ruby) – mliebelt Sep 30 '11 at 06:13

1 Answers1

2

No , It's the same thing but the first way is cleaner .

lesce
  • 6,224
  • 5
  • 29
  • 35