28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/setsumei/describable.rb', line 28
def collection_of klass, options = {}
self.class_eval do
include Enumerable
include Comparable
def each(*args,&block)
_internal_collection.each(*args,&block)
end
def include? value
_internal_collection.include? value
end
def <<(value)
_internal_collection << value
end
def [](value)
_internal_collection[value]
end
def []=(index,value)
_internal_collection[index] = value
end
def <=>(other)
_internal_collection <=> other || super
end
private
def _internal_collection
@_internal_collection ||= []
end
end
_defined_attributes[:_self] = Collection.of klass,options
end
|