Class: ActiveObject::Associations::HasManyAssociation::Collection
- Defined in:
- lib/active_object/associations.rb
Instance Method Summary collapse
-
#append(object) ⇒ Object
添加一个关联对象.
- #clear ⇒ Object
-
#delete(object) ⇒ Object
删除一个关联对象.
-
#each ⇒ Object
遍历关联对象集合.
- #each_with_index ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Collection
constructor
A new instance of Collection.
-
#insert(index, object) ⇒ Object
插入一个关联对象.
- #object_ids ⇒ Object
- #objects ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ Collection
Returns a new instance of Collection.
73 74 75 |
# File 'lib/active_object/associations.rb', line 73 def initialize() @objects = [] end |
Instance Method Details
#append(object) ⇒ Object
添加一个关联对象
90 91 92 |
# File 'lib/active_object/associations.rb', line 90 def append(object) @objects << object end |
#clear ⇒ Object
108 109 110 |
# File 'lib/active_object/associations.rb', line 108 def clear @objects.clear end |
#delete(object) ⇒ Object
删除一个关联对象
100 101 102 |
# File 'lib/active_object/associations.rb', line 100 def delete(object) @objects.delete(object) end |
#each ⇒ Object
遍历关联对象集合
77 78 79 80 81 |
# File 'lib/active_object/associations.rb', line 77 def each @objects.each do |object| yield object end end |
#each_with_index ⇒ Object
83 84 85 86 87 |
# File 'lib/active_object/associations.rb', line 83 def each_with_index @objects.each_with_index do |object,index| yield object,index end end |
#empty? ⇒ Boolean
112 113 114 |
# File 'lib/active_object/associations.rb', line 112 def empty? @objects.empty? end |
#insert(index, object) ⇒ Object
插入一个关联对象
95 96 97 |
# File 'lib/active_object/associations.rb', line 95 def insert(index,object) @objects.insert(index,object) end |
#object_ids ⇒ Object
116 117 118 |
# File 'lib/active_object/associations.rb', line 116 def object_ids @objects.collect{|object| object.id} end |
#objects ⇒ Object
120 121 122 |
# File 'lib/active_object/associations.rb', line 120 def objects @objects end |
#size ⇒ Object
104 105 106 |
# File 'lib/active_object/associations.rb', line 104 def size @objects.size end |