display/config/initializers/misc.rb
# Quick convenient way to convert array of objects to hash keyed on value determined by passed-in block.
#   x = %w(a bb ccc)
#   x.to_hash(&:size)    #  {1=>"a", 2=>"bb", 3=>"ddd"}
#   [1, 2, 3].to_hash    #  {1=>1, 2=>2, 3=>3}
Quick convenient way to convert array of objects to hash keyed on value determined by passed-in block.
Quick convenient way to convert array of objects to hash keyed on value determined by passed - in block .
def to_map(&block)
    inject({}) do |h, e|
      block_given? ? key = yield(e) : key = e
      h[key] = e
      h
    end
  end
def to_map ( & block ) inject ( { } ) do | h , e | block_given? ? key = yield ( e ) : key = e h [ key ] = e h end end
Quick convenient way to convert array of objects to hash keyed on value determined by passed-in block.
Quick convenient way to convert array of objects to hash keyed on value determined by passed - in block .
block