Skip to content

Repository files navigation

Ruby Facets cherries

Gem Version CI

More of Ruby, one method at a time. Facets is a collection of extensions to Ruby's core classes and standard library, plus a few small, reusable classes and modules. Most methods live in their own files, so you can load one extension, a class's extensions, or the core collection.

Facets took its name in 2004, growing out of a small methods library started in 2002, and is still maintained. The current release is 3.2.2, which requires Ruby 3.1 or newer. See the release history for changes and migration notes from earlier versions. The main branch also contains changes awaiting the next release.

Install

gem install facets

With Bundler, add this to your Gemfile:

gem 'facets', require: false

require: false lets you choose which extensions to load. Omit it if you want Bundler to load the core collection automatically.

Choose how much to load

One method

require 'facets/array/to_ranges'

[1, 2, 3, 6, 7].to_ranges
#=> [1..3, 6..7]

One class's core extensions

require 'facets/string'

'Ruby Facets'.snakecase
#=> "ruby_facets"

The core collection

require 'facets'

[1, 2, 3].average
#=> 2.0

require 'facets' loads the broadly useful core extensions: roughly 860 methods from 448 files, adding about 35 ms of load time and 2 MB of memory (Ruby 3.3, Linux). Some specialized core extensions are opt-in; require their method file directly. To load Facets extensions to a Ruby standard library, require that library through Facets:

require 'facets/ostruct'

This loads ostruct and Facets' OpenStruct extensions. On Ruby 3.5+, declare the ostruct gem separately because it is no longer a default gem.

Documentation

The split between lib/core, lib/standard and lib/rails is visible in API source paths. This helps you tell whether a method is loaded by require 'facets' or needs an explicit require. The lib/rails area, new in 4.0.0, holds Rails-compatible helpers; see the release history for details.

Contribute

Issues and pull requests are welcome. Start with CONTRIBUTING.md for the library's method organization, demos, and test conventions. The test suite runs with:

bundle install
bundle exec rake test

Source · Issues · Website

License and credits

Facets is distributed under the BSD 2-Clause License. Thomas Sawyer started the project, and many Rubyists have contributed code, ideas, tests, and documentation. Individual files record additional credits where applicable.

All your base are belong to Ruby.

About

Ruby Facets

Topics

Resources

Contributing

Stars

808 stars

Watchers

16 watching

Forks

Releases

Packages

Used by

Contributors

Languages