Skip to content
/ lupo Public

Includes Enumerable and provides an #each method for ruby objects

License

Notifications You must be signed in to change notification settings

snusnu/lupo

Repository files navigation

lupo

Gem Version Build Status Dependency Status Code Climate Coverage Status

Usage

# Remember that Enumerable#entries is part
# of ruby, so avoiding "entries" as the
# internal enumerable's name is a good idea
# if your enumerable is no array instance.

require 'lupo'

class TaskList
  include Lupo.enumerable(:tasks)

  def initialize(name, tasks)
    @name, @tasks = name, tasks
  end
end

list = TaskList.new('secret', %w[this and that])

list.each { |t| puts(t) }     # => list
list.each.to_a                # => ['this', 'and', 'that']
list.is_a?(Enumerable)        # => true
list.methods.include?(:tasks) # => false

class ItemList
  include Lupo.collection(:items)
end

list = ItemList.new(%w[this and that])

list.each { |i| puts(i) }               # => list
list.each.to_a                          # => ['this', 'and', 'that']
list.is_a?(Enumerable)                  # => true
list.protected_methods.include?(:items) # => true

other = ItemList.new(%w[this and that])

# see equalizer for detailed docs
list.equal?(other) # => false
list.eql?(other)   # => true
list == other      # => true

Credits

Contributing

See CONTRIBUTING.md for details.

Copyright

Copyright © 2013 Martin Gamsjaeger (snusnu). See LICENSE for details.

About

Includes Enumerable and provides an #each method for ruby objects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages