Class Enumerator
In: lib/core/facets/to_hash.rb
Parent: Object

Methods

Public Instance methods

Convert an Enumerator object into a hash. This is equivalent to Array#to_h.

  e1 = [[1,:a],[2,:b],[3,:c]].to_enum
  e1.to_h #=> { 1=>:a, 2=>:b, 3=>:c }

  e2 = [1,2,3,4,5].to_enum
  e2.to_h  #=> {5=>nil, 1=>2, 3=>4}

  e3 = [1,2,1,3,1,5].to_enum
  e3.to_h #=> {1=>5}

CREDIT: Sandor Szücs

[Source]

     # File lib/core/facets/to_hash.rb, line 285
285:   def to_h(mode=nil)
286:     to_a.to_h(mode)
287:   end

This is equivalent to Array#to_h_assoc.

[Source]

     # File lib/core/facets/to_hash.rb, line 309
309:   def to_h_assoc
310:     to_a.to_h_assoc
311:   end

This is equivalent to Array#to_h_auto.

[Source]

     # File lib/core/facets/to_hash.rb, line 291
291:   def to_h_auto
292:     to_a.to_h_auto
293:   end

This is equivalent to Array#to_h_flat.

[Source]

     # File lib/core/facets/to_hash.rb, line 303
303:   def to_h_flat
304:     to_a.to_h_flat
305:   end

This is equivalent to Array#to_h_multi.

[Source]

     # File lib/core/facets/to_hash.rb, line 315
315:   def to_h_multi
316:     to_a.to_h_multi
317:   end

This is equivalent to Array#to_h_splat.

[Source]

     # File lib/core/facets/to_hash.rb, line 297
297:   def to_h_splat
298:     to_a.to_h_splat
299:   end

[Validate]