Class: ActiveObject::Associations::HasManyAssociation::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/active_object/associations.rb

Instance Method Summary collapse

Constructor Details

#initializeCollection

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

#clearObject



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

#eachObject

遍历关联对象集合



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_indexObject



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

Returns:

  • (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_idsObject



116
117
118
# File 'lib/active_object/associations.rb', line 116

def object_ids
	@objects.collect{|object| object.id}
end

#objectsObject



120
121
122
# File 'lib/active_object/associations.rb', line 120

def objects
	@objects
end

#sizeObject



104
105
106
# File 'lib/active_object/associations.rb', line 104

def size
	@objects.size
end