
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
#+TITLE: FatCore Guide #+OPTIONS: toc:5 #+PROPERTY: header-args:ruby :colnames no :hlines yes :exports both :wrap example :ruby ruby #+PROPERTY: header-args:sh :exports code
[[https://travis-ci.org/ddoherty03/fat_core.svg?branch=master]]
#+begin_src ruby :results output puts "Current directory: #{Dir.pwd}" puts "Ruby LOADPATH:" $:.unshift("./lib") unless $:[0] == './lib' $:[0..10].each { |d| puts d } puts "..." require 'fat_core/all' # => true #+end_src
#+RESULTS: #+begin_example Current directory: /home/ded/src/fat_core Ruby LOADPATH: ./lib /home/ded/.rbenv/rbenv.d/exec/gem-rehash /home/ded/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0 /home/ded/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/x86_64-linux /home/ded/.rbenv/versions/3.4.1/lib/ruby/site_ruby /home/ded/.rbenv/versions/3.4.1/lib/ruby/vendor_ruby/3.4.0 /home/ded/.rbenv/versions/3.4.1/lib/ruby/vendor_ruby/3.4.0/x86_64-linux /home/ded/.rbenv/versions/3.4.1/lib/ruby/vendor_ruby /home/ded/.rbenv/versions/3.4.1/lib/ruby/3.4.0 /home/ded/.rbenv/versions/3.4.1/lib/ruby/3.4.0/x86_64-linux ... #+end_example
fat-core is a simple gem to collect core extensions and a few new classes
that I find useful in multiple projects.
** Installation
Add this line to your application's Gemfile:
#+begin_SRC ruby gem 'fat_core', :git => 'https://github.com/ddoherty03/fat_core.git' #+end_SRC
And then execute:
#+begin_src shell $ bundle #+end_src
Or install it yourself as:
#+begin_src shell $ gem install fat_core #+end_src
** Usage
You can extend classes individually by requiring the corresponding file:
#+begin_SRC ruby require 'fat_core/array' require 'fat_core/bigdecimal' require 'fat_core/enumerable' require 'fat_core/hash' require 'fat_core/kernel' require 'fat_core/numeric' require 'fat_core/range' require 'fat_core/string' require 'fat_core/symbol' #+end_SRC
Or, you can require them all:
#+begin_SRC ruby require 'fat_core/all' #+end_SRC
Many of these have little that is of general interest, but there are a few goodies.
*** Range
You can also extend the Range class with several useful methods that emphasize
coverage of one range by one or more others (#spanned_by? and #gaps),
contiguity of Ranges to one another (#contiguous?, #left_contiguous?, and
#right_contiguous?, #join), and the testing of overlaps between ranges
(#overlaps?, #overlaps_among?). These are put to good use in the
'fat_period' ([[https://github.com/ddoherty03/fat_period]]) gem, which combines
fat_core's extended Range class with its extended Date class to make a useful
Period class for date ranges, and you may find fat_core's extended Range class
likewise useful.
For example, you can use the #gaps method to find the gaps left in the
coverage on one Range by an Array of other Ranges:
#+begin_SRC ruby require 'fat_core/range' (0..12).gaps([(0..2), (5..7), (10..12)]) => [(3..4), (8..9)] #+end_SRC
*** Enumerable
FatCore::Enumerable extends Enumerable with the #each_with_flags method that
yields the elements of the Enumerable but also yields two booleans, first and
last that are set to true on respectively, the first and last element of the
Enumerable. This makes it easy to treat these two cases specially without
testing the index as in #each_with_index.
*** Hash
FatCore::Hash extends the Hash class with some useful methods for element
deletion (#delete_with_value) and for manipulating the keys
(#keys_with_value, #remap_keys and #replace_keys) of a Hash. It also
provides #each_pair_with_flags as an analog to Enumerable's
#each_with_flags.
It also provides the shovel operator as a convenient alias for Hash#merge,
so that
#+begin_src ruby :tangle no {a: 'A', b: 'B', c: 'C'} << {c: 'CC', d: 'DD'} << {e: 'EEE'} => {a: 'A', b: 'B', c: 'CC', d: 'DD', e: 'EEE'} #+end_src
*** String
FatCore::String has methods for performing matching of one string with another
(#matches_with, #fuzzy_match), for converting a string to title-case as
might by used in the title of a book (#entitle), for converting a String
into a useable Symbol (#as_sym) and vice-versa (#as_str also
Symbol#as_str), for wrapping with an optional hanging indent (#wrap),
cleaning up errant spaces (#clean), and computing the Damerau-Levenshtein
distance between strings (#distance). And several others.
*** TeX Quoting
Several of the extension, most notably 'fat_core/string', provides a
#tex_quote method for quoting the string version of an object so as to allow
its inclusion in a TeX document and quote characters such as '$' or '%' that
have a special meaning for TeX.
*** Numbers
FatCore::Numeric has methods for inserting grouping commas into a number
(#commas and #group), for converting seconds to HH:MM:SS.dd format
(#secs_to_hms), for testing for integrality (#whole? and #int_if_whole), and
testing for sign (#signum).
** Contributing
FAQs
Unknown package
We found that fat_core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.