Module: Recliner::Properties::Set::ClassMethods
- Defined in:
- lib/recliner/properties/set.rb
Instance Method Summary collapse
-
#Set(type) ⇒ Object
Creates a new Set class with the given type.
Instance Method Details
#Set(type) ⇒ Object
Creates a new Set class with the given type. A Set operates like an Array, but has strict type enforcement. It also automatically converts its elements to the correct type when loading from couch format.
Set classes are cached so that:
Set(String).object_id == Set(String).object_id
Example
>> Set(String) # creates a set which can contain String elements
>> Set(Address) # creates a set which can contain Address elements
# (Address must be serializable to/from couch format)
23 24 25 26 27 28 29 30 |
# File 'lib/recliner/properties/set.rb', line 23 def Set(type) @set_class_cache ||= {} @set_class_cache[type] ||= begin returning Class.new(Recliner::Set) do |klass| klass.type = type end end end |