Module: Curio::Methods

Extended by:
Forwardable
Defined in:
lib/curio.rb

Overview

The collection methods

Instance Method Summary collapse

Instance Method Details

#<<(item) ⇒ self

Add an item to the collection

Parameters:

Returns:

API:

  • public



133
134
135
136
137
# File 'lib/curio.rb', line 133

def <<(item)
  key = coerce_key item.send(key_method)
  @map[key] = item
  self
end

#[](key) ⇒ object

Get an item from the collection

Parameters:

Returns:

API:

  • public



163
164
165
# File 'lib/curio.rb', line 163

def [](key)
  fetch key, nil
end

#fetch(key, *args) {|undefined| ... } ⇒ object

Fetch an item from the collection

Parameters:

Yields:

  • (undefined)

Returns:

API:

  • public



149
150
151
152
153
154
# File 'lib/curio.rb', line 149

def fetch(key, *args, &block)
  args.unshift coerce_key(key)
  @map.fetch(*args, &block)
rescue KeyError
  raise NotFoundError, key
end

#initializeundefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Setup the map and call parent initializer

Returns:

API:

  • private



111
112
113
114
# File 'lib/curio.rb', line 111

def initialize(*)
  @map = { }
  super
end

#key?(key) ⇒ Boolean Also known as: has?

Check if collection has an item with specified key

Parameters:

Returns:

API:

  • public



174
175
176
# File 'lib/curio.rb', line 174

def key?(key)
  @map.key? coerce_key(key)
end

#to_hHash

Returns a hash representation of the collection

Returns:

API:

  • public



184
185
186
# File 'lib/curio.rb', line 184

def to_h
  @map
end

#valuesArray Also known as: all

Get all the items in collection

Returns:

API:

  • public



97
# File 'lib/curio.rb', line 97

def_delegators :values, :each