module NaturalSort

Public: The public interface for NaturalSort module For method descriptions refer to NaturalSort::Engine

Examples

require 'natural_sort'
NaturalSort.sort ['a1', 'a12', 'a2']  #=> ['a1', 'a2', 'a12']

# or

require 'natural_sort_kernel'
['a', 'b', 'A', 'B'].natural_sort     #=> ['A', 'a', 'B', 'b']

Public Class Methods

naturalsort(object) click to toggle source

Deprecated: Alias to NaturalSort.sort. Was deprecated in version 1.2.0. To be removed in version 2.0.0 (according to semver)

object - the object to sort, which must either be an Enumerable or implement to_a to be meaningful.

Returns a sorted version of the object.

# File lib/natural_sort/base.rb, line 42
def naturalsort(object)
  warn('NaturalSort.naturalsort is deprecated and will be removed. Use NaturalSort.sort instead')
  NaturalSort::Engine.sort(object)
end

Public Instance Methods

natural_sort() click to toggle source

Public: Main method to sort (other are just aliases). To be used when including NaturalSort into another object. Delegates to NaturalSort::Engine.sort

Note that the object must either be an Enumerable or implement to_a to be meaningful.

Returns a sorted version of the object.

Examples

require 'natural_sort'

class MyObject
  include NaturalSort
  def to_a
    ['a3, a2, a1']
  end
end
# File lib/natural_sort/base.rb, line 65
def natural_sort
  NaturalSort::Engine.sort(self)
end