Curio
¶ ↑
A module to ease creation of collections and enumerable maps
Installation¶ ↑
Add this line to your application's Gemfile:
gem 'curio'
And then execute:
$ bundle
Or install it yourself as:
$ gem install curio
Usage¶ ↑
Item = Struct.new :id class Collection include Curio.new :id, Integer end collection = Collection.new collection << Item.new(1) collection << Item.new(2) collection.fetch 1 # => #<struct Item id=1> collection.fetch '1' # => #<struct Item id=1> collection.fetch 3 # => Curio::NotFoundError: Item not found in collection with key: 3 collection.fetch 3, :default # => :default collection.fetch 3 do :default end # => :default collection[1] # => #<struct Item id=1> collection['1'] # => #<struct Item id=1> collection[3] # => nil collection.key? 1 # => true collection.key? '1' # => true collection.key? 3 # => false collection.all # => [#<struct Item id=1>, #<struct Item id=2>] collection.last # => #<struct Item id=2> collection.each do |item| puts item.id end # => 1 2
Contributing¶ ↑
-
Fork it ( github.com/terlar/curio/fork )
-
Create your feature branch (
git checkout -b my-new-feature
) -
Commit your changes (
git commit -am 'Add some feature'
) -
Push to the branch (
git push origin my-new-feature
) -
Create a new Pull Request