Skip to content

shivam091/core_extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rb_core_extensions

rb_core_extensions is a set of core extensions beyond those provided by Ruby and ActiveSupport.

Ruby Gem Version Gem Downloads Test Coverage Maintainability License

Minimum Requirements

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

  1. #take! - Alters the array by removing first n elements.

core_extensions/array/math.rb

  1. round - Rounds each element of the numeric array up to specified precision.
  2. mean - Returns the mean of the array of Numeric.
  3. variance - Returns the variance of the array of Numeric.
  4. stddev - Returns the standard deviation of the array of Numeric.

core_extensions/array/duplicates.rb

  1. duplicates - Returns an array of the duplicate elements.

core_extensions/array/inclusion.rb

  1. include_any? - Returns whether the array contains any of the elements.
  2. include_none? - Returns whether the array contains none of the elements.
  3. include_all? - Returns whether the array contains all of the elements.
  4. includes_index? - Returns whether the array has a value at the specified index.

core_extensions/hash/inclusion.rb

  1. #keys? - Returns whether the hash contains all of the specified keys.

core_extensions/hash/access.rb

  1. #keys_at - Returns the array of keys of an occurrence of given values.

core_extensions/hash/delete.rb

  1. #slice! - Alters the hash by keeping only specified keys and returns it.

core_extensions/true_class.rb

  1. #to_i - Returns 1 if invoked on TrueClass instance.
  2. #to_b - Returns true if invoked on TrueClass instance.

core_extensions/false_class.rb

  1. #to_i - Returns 0 if invoked on FalseClass instance.
  2. #to_b - Returns false if invoked on FalseClass instance.

core_extensions/nil_class.rb

  1. #blank? - Returns true if invoked on NilClass instance.
  2. #to_b - Returns false if invoked on NilClass instance.

core_extensions/object.rb

  1. #is_one_of? - Returns true if the receiver object is an instance of at least one of the classes specified by args.
  2. #deep_send - Invokes the specified methods continuously, unless encountering a nil value.
  3. #in_namespace? - Returns whether or not the object is in the given namespace.

core_extensions/module.rb

  1. #namespaces - Returns an Array with the namespaces to the current Module.

core_extensions/class.rb

  1. #hierarchy - Returns a tree-like Hash structure of all descendants.
  2. #lineage - Returns an Array of all superclasses.
  3. #leaf_subclasses - Returns an Array of all descendants which have no subclasses.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Copyright 2023 Harshal V. LADHE, Released under the MIT License.