Method: Immutable::Vector#sort_by

Defined in:
lib/immutable/vector.rb

#sort_by {|element| ... } ⇒ Vector

Return a new Vector with the same items, but sorted. The sort order is determined by mapping the items through the given block to obtain sort keys, and then sorting the keys according to their natural sort order (‘#<=>`).

Examples:

Immutable::Vector["Elephant", "Dog", "Lion"].sort_by { |e| e.size }
# => Immutable::Vector["Dog", "Lion", "Elephant"]

Yields:

  • (element)

    Once for each element.

Yield Returns:

  • a sort key object for the yielded element.

Returns:



708
709
710
# File 'lib/immutable/vector.rb', line 708

def sort_by
  self.class.new(super)
end