Sha256: 7a76112f42f63d17b0ed21a4d29b50449740d26285dcb678fabdaa1dd19f234d

Contents?: true

Size: 382 Bytes

Versions: 1

Compression:

Stored size: 382 Bytes

Contents

class Array
  class ExpectedOneElementError < StandardError; end

  # To make sanity checking a bit easier.
  def only
    raise ExpectedOneElementError unless count == 1
    first
  end

  def hashify
    each_with_object({}) do |item, hash|
      hash[item.id] = item
    end
  end

  # For readability, especially after sorting.
  alias :highest :last
  alias :lowest :first
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
junk_drawer-0.0.7 lib/core_extensions/array.rb