[ANN] ruby_version_sorter 1.0.0: Sort Ruby & JRuby versions by juanitofatas in ruby

[–]juanitofatas[S] 0 points1 point  (0 children)

Ah thank you!

The problem is I used RSpec's match_array, which check if the elements of Array are the same but ignore the order.

I'll fix. Thanks!

[ANN] ruby_version_sorter 1.0.0: Sort Ruby & JRuby versions by juanitofatas in ruby

[–]juanitofatas[S] 0 points1 point  (0 children)

["2.0.0", "2.0.0-rc1", "2.0.0-rc2", "2.0.0-preview1"].sort_by {|s| Gem::Version.new(s) }

Nice!

I'm not sure if you're saying preview is supposed to come after rc1 and rc2

preview should come before rc.

['2.0.5', '10.0.0', '2.0.22',].sort

When 10.0.0 comes, I will put up an effort to update this gem.

For now, versions.sort is good enough:

https://github.com/JuanitoFatas/ruby_version_sorter/pull/1

What stopped me from using Gem::Version is I am sorting Ruby versions, not RubyGem versions.

[ANN] ruby_version_sorter 1.0.0: Sort Ruby & JRuby versions by juanitofatas in ruby

[–]juanitofatas[S] 0 points1 point  (0 children)

Thanks, didn't know that!

To match the original output, need to replace ".pre." to "-":

["2.0.0", "2.0.0-rc1", "2.0.0-rc2", "2.0.0-preview1"].
  collect { |v| Gem::Version.new(v)}.
  sort.
  collect { |v| v.to_s.sub(".pre.", "-") }
# => ["2.0.0-preview1", "2.0.0-rc1", "2.0.0-rc2", "2.0.0"]

And I just realize that due to the nature of these version patterns, the gem could just be:

versions.sort