🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

sorting

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sorting

0.0.2
98

Supply Chain Security

100

Vulnerability

100

Quality

100

Maintenance

100

License

Unpopular package

Quality

This package is not very popular.

Found 1 instance in 1 package

Uses eval

Supply chain risk

Package uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.

Found 1 instance in 1 package

Version published
Maintainers
1
Created

README

Summary

Helpful functionality for sorting and comparing.

Installation

gem install sorting

Usage

Sort a list of Person objects

# Convenient
require 'sorting/convenience'
people.sort_by { |person| [asc(person.first_name), asc(person.last_name), desc(person.age)] }

# Or without patching Kernel
require 'sorting'
people.sort_by { |person|
  [Sorting.asc(person.first_name), Sorting.asc(person.last_name), Sorting.desc(person.age)]
}

# Care about expensive comparison values which may not always be needed
# assume item.expensive_value takes a lot of time to compute, but since it's the second value,
# it might only be needed in a small number of cases.
require 'sorting/convenience'
items.sort_by { |item|
  [asc(item.cheap_value), asc(:nils_last) { item.expensive_value }]
}

# Care about nil values in your data
require 'sorting/convenience'
people.sort_by { |person|
  [asc(person.first_name, :nils_first), asc(person.first_name, :nils_last)]
}

# Only care about nil values in your data
[5,3,nil,9].sort_by { |x| x || Sorting::Bigger } # Sorting::Smaller is available too

Take a look at {file:documentation/examples.rb} for more examples.

License

You can use this code under the {file:LICENSE.txt BSD-2-Clause License}, free of charge. If you need a different license, please ask the author.

FAQs

Package last updated on 23 Feb 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts