我需要从实例方法调用weight_to_kg
类方法。
我想为我的许多模型创建重量到公斤的转换器,这些模型的重量列以磅为单位。
module WeightConvertor
extend ActiveSupport::Concern
def weight_kg
# I need to call weight_to_kg method
ClassMethods.weight_to_kg(weight) # does not work
end
module ClassMethods
def weight_to_kg(weight)
end
end
end
class Order < ActiveRecord::Base
include WeightConvertor
# weight column is present
end
Order.first.weight
Order.first.weight_kg
我该怎么做?