Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/transcode/string.rb

Overview

Adds a natural sort method. It converts a string such as "Filename 10" into an array with floats in place of numbers, ["Filename", 10.0], as suggested in https://stackoverflow.com/q/4078906.

Instance Method Summary collapse

Instance Method Details

#naturalizedObject



11
12
13
# File 'lib/transcode/string.rb', line 11

def naturalized
  scan(/[^\d.]+|[\d.]+/).map { |f| f.match?(/\d+(\.\d+)?/) ? f.to_f : f }
end