Table of Contents

Refinements

Gem Version Code Climate GPA Code Climate Coverage Gemnasium Status Travis CI Status Patreon

Provides a collection of refinements for core Ruby objects.

Table of Contents

Features

  • Adds Array refinements:
    • Array#compress - Removes nil and empty values without modifying original values.
    • Array#compress! - Removes nil and empty values and modifies original values.
  • Adds BigDecimal refinements:
    • BigDecimal#inspect - Allows one to inspect a big decimal with numeric representation.

Requirements

  1. MRI 2.x.x.

Setup

For a secure install, type the following from the command line (recommended):

gem cert --add <(curl -Ls http://www.my-website.com/gem-public.pem)
gem install refinements --trust-policy MediumSecurity

NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while allowing the installation of unsigned dependencies since they are beyond the scope of this gem.

For an insecure install, type the following (not recommended):

gem install refinements

Add the following to your Gemfile file:

gem "refinements"

Usage

Requires

Due to this gem being a collection of Ruby refinements, none of the refinements are auto-loaded by default in order to reduce code bloat for your app. Instead, require the specific requirement for the code that needs it. You'll want to require one or all of the following:

require "refinements/array_extensions"
require "refinements/big_decimal_extensions"

Using

In addition to requiring the appropriate refinement file for the code that needs it, you'll also need to use the refinement by using the using keyword within your object. You'll want to use one or all of the following:

class Example
  using Refinements::ArrayExtensions
  using Refinements::BigDecimalExtensions
end

Examples

With the appropriate refinements required and used within your objects, the following sections demonstrates how each refinement enriches your objects with new capabilities.

Array

example = ["An", nil, "", "Example"]
example.compress # => ["An", "Example"]
example # => ["An", nil, "", "Example"]

example = ["An", nil, "", "Example"]
example.compress! # => ["An", "Example"]
example # => ["An", "Example"]

Big Decimal

big = BigDecimal.new "5.0E-10"
big.inspect # => "#<BigDecimal:3fd3d458fe84 0.0000000005>"

Tests

To test, run:

bundle exec rake

Versioning

Read Semantic Versioning for details. Briefly, it means:

  • Patch (x.y.Z) - Incremented for small, backwards compatible bug fixes.
  • Minor (x.Y.z) - Incremented for new, backwards compatible public API enhancements and/or bug fixes.
  • Major (X.y.z) - Incremented for any backwards incompatible public API changes.

Code of Conduct

Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.

Contributions

Read CONTRIBUTING for details.

License

Copyright (c) 2015 Alchemists. Read the LICENSE for details.

History

Read the CHANGELOG for details. Built with Gemsmith.

Credits

Developed by Brooke Kuhlmann at Alchemists.