lib/collection_of/collection.rb in collection_of-1.0.1 vs lib/collection_of/collection.rb in collection_of-1.0.2
- old
+ new
@@ -49,9 +49,19 @@
checker = @options.fetch(:allow_subclasses, true) ? :is_a? : :instance_of?
raise ArgumentError, "can only add #{@klass.name} objects" unless obj.send(checker, @klass)
@collection << obj
end
+ def keys
+ @collection.map{ |i| i.name.to_sym }
+ end
+
+ def include?(item)
+ return true if @collection.include?(item)
+ return keys.include?(item.to_sym) if item.respond_to?(:to_sym)
+ return false
+ end
+
def except(*items)
items.map!(&:to_sym)
self.class.new(klass, reject{ |i| items.include?(i.name.to_sym) })
end
\ No newline at end of file