File: README.md

package info (click to toggle)
ruby-version-sorter 2.2.4-1~bpo10+1
  • links: PTS, VCS
  • area: main
  • in suites: buster-backports
  • size: 164 kB
  • sloc: ansic: 247; ruby: 112; sh: 52; makefile: 8
file content (36 lines) | stat: -rw-r--r-- 778 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Version sorter

Fast sorting of strings representing version numbers.

```rb
require 'version_sorter'

versions = ["1.0.9", "2.0", "1.0.10", "1.0.3", "2.0.pre"]

VersionSorter.sort(versions)
#=> 1.0.3
#=> 1.0.9
#=> 1.0.10
#=> 2.0.pre
#=> 2.0
```

You can also sort arrays of arbitrary objects by providing a block.

```rb
VersionSorter.sort(tags) { |tag| tag.name }
```

Library API:

```rb
VersionSorter.sort(versions)   #=> sorted array
VersionSorter.rsort(versions)  #=> reverse sorted array

VersionSorter.sort!(versions)  # sort array in place
VersionSorter.rsort!(versions) # reverse sort array in place

VersionSorter.compare(version_a, version_b) #=> positive or negative number depending on which way to sort 
```

<http://github.com/blog/521-speedy-version-sorting>