1
런타임에 객체 (ActiveRecord :: Base의 인스턴스)를 확장하고 클래스 메서드 (has_many
연결을 추가)를 호출하고 싶습니다. 로하고 싶은 나의 이상적인 코드는 다음과 같습니다런타임시 오브젝트를 확장 할 때 클래스 메소드를 호출하는 방법은 무엇입니까?
class User < ActiveRecord::Base
end
module Seller
has_many :bookings, :foreign_key => :seller_id
end
module Buyer
has_many :bookings, :foreign_key => :buyer_id
end
user = User.find(1)
user.extend Seller
user.bookings
나는 User
클래스에 모듈을 포함하지 않습니다 유의하시기 바랍니다, 내가 하나의 사용자 개체, 모든 사용자 개체의 동작을 확장 할.