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.
gem install facetsWith Bundler, add this to your Gemfile:
gem 'facets', require: falserequire: false lets you choose which extensions to load. Omit it if you want Bundler to load the core collection automatically.
require 'facets/array/to_ranges'
[1, 2, 3, 6, 7].to_ranges
#=> [1..3, 6..7]require 'facets/string'
'Ruby Facets'.snakecase
#=> "ruby_facets"require 'facets'
[1, 2, 3].average
#=> 2.0require '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.
- Getting started and loading guide
- Generated API documentation on RubyDoc.info (check the displayed version)
- Release history
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.
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 testFacets 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.