Sha256: 60f7594e115b5d06fb878c7d0c8f73ba34d440000eb58eecab0ebd66fe3e7e82
Contents?: true
Size: 608 Bytes
Versions: 30
Compression:
Stored size: 608 Bytes
Contents
class Array # returns the first element of a 2-element array. # useful when dealing with hashes in array form. # e.g., pairs.map(&:key) def key size == 2 or raise 'array must contain exactly two elements' first end # returns the second element of a 2-element array. # useful when dealing with hashes in array form. # e.g., pairs.map(&:value) def value size == 2 or raise 'array must contain exactly two elements' last end # A backport of Array@to_h from Ruby 2.1 unless instance_methods.include?(:to_h) define_method(:to_h) do Hash[self] end end end
Version data entries
30 entries across 30 versions & 1 rubygems