2011-09-30 6 views
2
내가 다음 코드 한

: 테스트 코드의 사실루비 믹스 : 확장 또는 포함?

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 

모두 2 줄 작동합니다. 그래서 'extend'과 'include'(싱글 톤 클래스 : self) 사이에 어떤 차이가 있습니까?

+2

[루비에서 포함과 확장의 차이점은 무엇입니까?] (http://stackoverflow.com/questions/156362/what-is-the-difference-between-include-and-extend- 루비에서) – mliebelt

답변

2

아니요, 똑같은 문제이지만 첫 번째 방법은 더 깨끗합니다.