Ich habe mich gefragt, wie ich Klassenvariablen von ModulenWie kann man auf Klassenvariablen vom Modul zugreifen?
module Entity
def foo
# puts @@rules
end
end
class Person
include Entity
attr_accessor :id, :name
@@rules = [[:id, :int, :not_null],
[:name, :string, :not_null]]
end
class Car
include Entity
attr_accessor :id, :year
@@rules = [[:id, :string, :not_null],
[:year:, :int, :not_null]]
end
p = Person.new
c = Car.new
p.foo # [[:id, :int, :not_null], [:name, :string, :not_null]]
c.foo # [[:id, :string, :not_null], [:year, :int, :not_null]]
Ich nahm noch einen Blick auf cattr_accessor
und mattr_accessor
von ActiveSupport
, zugreifen kann, sondern eine Art zu lösen, nicht finden kann.
Nun, ty! Der Code funktioniert und das ist großartig! Ich hoffe eine Antwort, in der der Code eleganter wäre! – Quarktum