Module: NaturalSort

Extended by:
Forwardable
Included in:
Array, Enumerable, Hash, Set
Defined in:
lib/natural_sort/base.rb,
lib/natural_sort/version.rb

Overview

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']

Defined Under Namespace

Modules: Engine, Kernel, Version

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.naturalsort(object) ⇒ Object

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.



42
43
44
45
# 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

Instance Method Details

#natural_sortObject

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


65
66
67
# File 'lib/natural_sort/base.rb', line 65

def natural_sort
  NaturalSort::Engine.sort(self)
end