rb_core_extensions
rb_core_extensions
is a set of core extensions beyond those provided by Ruby
and ActiveSupport
.
Minimum Requirements
- Ruby 3.2.2+ (https://www.ruby-lang.org/en/downloads/branches/)
Installation
If using bundler, first add this line to your application's Gemfile:
gem 'rb_core_extensions'
And then execute:
$ bundle install
Or otherwise simply install it yourself as:
$ gem install rb_core_extensions
Usage
Loading all core extensions at once:
require "core_extensions/all"
Cherry-picking only what you want:
require "core_extensions/array"
require "core_extensions/array/math"
require "core_extensions/date"
Extensions Provided
Below are the extension methods provided by rb_core_extensions
. Please refer documentation for examples of how to use these methods.
core_extensions/array/delete.rb
-
#take!
- Alters the array by removing firstn
elements.
core_extensions/array/math.rb
-
round
- Rounds each element of the numeric array up to specifiedprecision
. -
mean
- Returns the mean of the array ofNumeric
. -
variance
- Returns the variance of the array ofNumeric
. -
stddev
- Returns the standard deviation of the array ofNumeric
.
core_extensions/array/duplicates.rb
-
duplicates
- Returns an array of the duplicate elements.
core_extensions/array/inclusion.rb
-
include_any?
- Returns whether the array contains any of theelements
. -
include_none?
- Returns whether the array contains none of theelements
. -
include_all?
- Returns whether the array contains all of theelements
. -
includes_index?
- Returns whether the array has a value at the specifiedindex
.
core_extensions/hash/inclusion.rb
-
#keys?
- Returns whether the hash contains all of the specifiedkeys
.
core_extensions/hash/access.rb
-
#keys_at
- Returns the array of keys of an occurrence of givenvalues
.
core_extensions/hash/delete.rb
-
#slice!
- Alters the hash by keeping only specifiedkeys
and returns it.
core_extensions/true_class.rb
-
#to_i
- Returns1
if invoked onTrueClass
instance. -
#to_b
- Returnstrue
if invoked onTrueClass
instance.
core_extensions/false_class.rb
-
#to_i
- Returns0
if invoked onFalseClass
instance. -
#to_b
- Returnsfalse
if invoked onFalseClass
instance.
core_extensions/nil_class.rb
-
#blank?
- Returnstrue
if invoked onNilClass
instance. -
#to_b
- Returnsfalse
if invoked onNilClass
instance.
core_extensions/object.rb
-
#is_one_of?
- Returnstrue
if the receiver object is an instance of at least one of the classes specified byargs
. -
#deep_send
- Invokes the specified methods continuously, unless encountering anil
value. -
#in_namespace?
- Returns whether or not the object is in the given namespace.
core_extensions/module.rb
-
#namespaces
- Returns anArray
with the namespaces to the currentModule
.
core_extensions/class.rb
-
#hierarchy
- Returns a tree-likeHash
structure of all descendants. -
#lineage
- Returns anArray
of all superclasses. -
#leaf_subclasses
- Returns anArray
of all descendants which have no subclasses.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
Copyright 2023 Harshal V. LADHE, Released under the MIT License.