Sha256: 7f61432c3f8261f42bc64e2640933e93f4080f486b78ae24faa72fad04c6c199
Contents?: true
Size: 1.1 KB
Versions: 3
Compression:
Stored size: 1.1 KB
Contents
module ActiveMocker module Collection class Base include Enumerable def initialize(collection=[]) @collection = [*collection] end def <<(*records) collection.concat(records.flatten) end delegate :take, :push, :clear, :first, :last, :concat, :replace, :distinct, :uniq, :count, :size, :length, :empty?, :any?, :include?, :delete, to: :collection alias distinct uniq # def delete(obj) # collection.delete(obj) # end def order(key) self.class.new(collection.sort_by{ |item| item.send(key) }) end def reverse_order self.class.new(collection.reverse) end def select(&block) self.class.new(collection.select(&block)) end def each(&block) self.class.new(collection.each do |item| block.call(item) end) end def to_a @collection end def ==(val) return false if val.nil? collection.hash == val.hash end private def collection @collection end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
active_mocker-1.3.2 | lib/active_mocker/collection/base.rb |
active_mocker-1.3.1 | lib/active_mocker/collection/base.rb |
active_mocker-1.3 | lib/active_mocker/collection/base.rb |