Module: Sortsmith

Defined in:
lib/sortsmith.rb,
lib/sortsmith/sorter.rb,
lib/sortsmith/version.rb

Overview

Sortsmith provides a flexible, chainable API for sorting Ruby collections.

The gem extends Ruby's built-in Enumerable module to provide an intuitive sorting interface that reads like natural language and supports complex sorting operations through method chaining.

Examples:

Basic usage

users = ["Charlie", "alice", "Bob"]
users.sort_by.downcase.sort
# => ["alice", "Bob", "Charlie"]

Hash sorting

users = [
  { name: "Charlie", age: 25 },
  { name: "alice", age: 30 },
  { name: "Bob", age: 20 }
]
users.sort_by.dig(:name).insensitive.sort
# => sorted by name, case-insensitive

Complex chaining

users.sort_by.dig(:name, indifferent: true).downcase.desc.sort
# => Extract name (works with both string/symbol keys), downcase, descending

See Also:

Author:

  • Bryan "itsthedevman"

Since:

  • 0.1.0

Defined Under Namespace

Classes: Error, Sorter

Constant Summary collapse

VERSION =

The current version of the Sortsmith gem

Since:

  • 0.1.0

"1.0.1"