Sha256: 0ca4cf6a99897fc169aa95adc6410172f44de7adaae15dc6f9ee094ab6525a01

Contents?: true

Size: 451 Bytes

Versions: 3

Compression:

Stored size: 451 Bytes

Contents

module Enumerable

  # Similar to #group_by but returns an array of the groups.
  # Returned elements are sorted by block.
  #
  #    %w{this is a test}.organize_by {|x| x[0]}
  #    #=> [ ['a'], ['is'], ['this', 'test'] ]
  #
  # CREDIT: Erik Veenstra

  def organize_by(&b)
    group_by(&b).sort.transpose.pop || []   # group_by(&b).values ?
  end

  # DEPRECATED: Name changed to avoid confusion with #cluster.
  alias cluster_by organize_by

end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/enumerable/organize_by.rb
facets-3.1.0 lib/core/facets/enumerable/organize_by.rb
facets-3.0.0 lib/core/facets/enumerable/organize_by.rb