1
현재 특정 상수 배열에 인덱스를 나타내는 ID를 데이터베이스에 저장해야합니다. 저는 항상 이와 같은 방법을 사용하고 있습니다.이 보석이 있습니까?
class Foo
ARY = [ :a :b, :c ]
def bar
return ARY[self.bar_id]
end
def bar=(value)
return self.bar_id=ARY.index(value)
end
scope :a, -> { where(:bar_id => ARY.index(:a)) }
scope :b, -> { where(:bar_id => ARY.index(:b)) }
scope :c, -> { where(:bar_id => ARY.index(:c)) }
def a?
return bar == :a
end
def b?
return bar == :b
end
def c?
return bar == :c
end
end
이 작업을 수행하는 보석이 존재합니까? simple_enum 보석 클래스와
원더풀! 답장을 보내 주셔서 감사합니다 – pierallard