Ruby Gems

Companion site to the book Practical Ruby Gems: Installation, Distribution, and Beyond, Second Edition, by David Berube.

bigdecimal

bigdecimal provides arbitrary-precision decimal arithmetic in Ruby, essential for financial calculations and any domain requiring exact decimal representation. Unlike Ruby's Float type which uses binary floating-point arithmetic prone to rounding errors, BigDecimal performs decimal arithmetic with user-specified precision, eliminating common floating-point issues. The gem (formerly in Ruby's standard library) ensures calculations involving money, percentages, or measurements maintain exact decimal precision. The library represents numbers in decimal form with configurable precision, supporting the full range of arithmetic operations including addition, subtraction, multiplication, division, and mathematical functions. It handles precision control explicitly, allowing developers to specify significant digits and rounding modes according to business rules or standards. BigDecimal provides accurate comparison operations, conversion to and from other numeric types, and serialization for storage. The gem implements IEEE 854 decimal arithmetic specifications, ensuring consistent behavior across platforms and use cases. bigdecimal is critical for financial applications, accounting systems, e-commerce platforms, and any domain where decimal precision errors are unacceptable. It's used in payment processing, tax calculations, currency conversions, and scientific calculations requiring exact decimal representation. Applications handling money should always use BigDecimal rather than Float to avoid accumulating rounding errors that, while tiny, can cause reconciliation problems, incorrect tax calculations, or regulatory compliance issues. The gem's precise decimal arithmetic makes it the foundation for reliable financial computations in Ruby.

bundler-trivy

bundler-trivy is a Bundler plugin that integrates Aqua Security's Trivy vulnerability scanner into the Ruby dependency management workflow. The plugin automatically scans Gemfile.lock for known security vulnerabilities in dependencies, bringing container and infrastructure scanning capabilities to Ruby projects. It provides an additional security layer by checking dependencies against Trivy's vulnerability databases during bundle operations. The plugin hooks into Bundler's lifecycle to run Trivy scans after dependency resolution, reporting vulnerabilities with severity ratings, CVE identifiers, and remediation guidance. It leverages Trivy's comprehensive vulnerability databases covering not just Ruby gems but also dependencies' native extensions and system libraries. bundler-trivy supports configurable severity thresholds, allowing teams to fail builds on high-severity vulnerabilities while warning on lower-severity issues. The plugin can output results in multiple formats for integration with CI/CD pipelines and security dashboards. bundler-trivy is essential for security-conscious Ruby applications, particularly those requiring compliance with security standards or handling sensitive data. It's valuable in CI/CD pipelines where automated vulnerability scanning prevents insecure dependencies from reaching production. The plugin complements tools like bundler-audit by leveraging Trivy's broader vulnerability database and integration with infrastructure scanning workflows. It's particularly useful for organizations already using Trivy for container scanning who want consistent vulnerability scanning across their infrastructure and application dependencies.

bzip2-ffi

bzip2-ffi provides Ruby bindings to the bzip2 compression library using FFI (Foreign Function Interface). bzip2 is a block-sorting compression algorithm that typically achieves better compression ratios than gzip, particularly on text and similar data, at the cost of slower compression and decompression speeds. The gem offers Ruby access to bzip2's compression capabilities without requiring compiled C extensions, using FFI for cross-platform compatibility. The library implements bzip2's compression and decompression through a pure Ruby interface that dynamically loads the system's libbz2 library. It provides methods for compressing and decompressing data, supporting both in-memory operations and streaming processing of large files. The gem handles bzip2's block-based compression format, which allows parallel decompression and provides some fault tolerance where a corrupt block doesn't prevent decompressing other blocks. Using FFI rather than compiled extensions makes the gem work across Ruby implementations and platforms without recompilation. bzip2-ffi is useful for applications requiring maximum compression ratios for archived data, working with bzip2-compressed files, or needing cross-platform compression without compiled dependencies. It's particularly suited for compressing text, source code, and log files where bzip2's algorithm performs well. While slower than newer algorithms like zstd, bzip2 remains relevant for compatibility with existing compressed archives and systems where compression ratio matters more than speed, especially when decompression performance is acceptable.

curb

curb is a Ruby binding to libcurl, providing a fast, full-featured HTTP client library. Named for "Curl-RuBy", it wraps libcurl's proven networking capabilities, offering support for HTTP, HTTPS, FTP, and numerous other protocols with robust connection handling. The gem provides Ruby access to libcurl's extensive feature set including connection pooling, authentication methods, and protocol options. The library offers both easy and multi interfaces, where the easy interface handles single requests with straightforward method calls, while the multi interface enables concurrent requests for improved performance. It supports features like cookie handling, custom headers, SSL configuration, proxy support, and authentication schemes including Basic, Digest, and NTLM. curb includes support for streaming responses, upload and download progress callbacks, and connection reuse for improved efficiency. Its C extension provides performance advantages over pure Ruby HTTP clients, particularly for high-throughput scenarios. curb excels in applications requiring high-performance HTTP operations, API clients making many concurrent requests, or systems needing libcurl's advanced protocol support and battle-tested reliability. It's particularly valuable in web scraping, API integration, file transfer applications, and monitoring systems where connection efficiency and protocol support matter. The gem's direct libcurl binding provides both performance and access to HTTP features that may not be available in higher-level Ruby HTTP libraries.

ffi-libc

ffi-libc provides Ruby FFI bindings to the C standard library (libc), exposing fundamental system functions that aren't available through Ruby's standard library. The gem wraps essential libc functions for memory management, string operations, file operations, time handling, and system calls, giving Ruby programs access to low-level system capabilities. It builds on the ffi gem's Foreign Function Interface to define function signatures and handle C calling conventions. The library exposes functions like malloc/free for manual memory management, memcpy/memset for memory operations, and system functions not wrapped by Ruby's File or Dir classes. It provides access to process control functions, signal handling, environment variables, and low-level I/O operations. ffi-libc handles C string encoding, pointer manipulation, and struct marshalling through FFI's type system. The gem works across platforms by relying on the standard C library present on all systems, though specific function availability may vary by platform. ffi-libc is useful when porting C code to Ruby, interfacing with system APIs not exposed by Ruby's standard library, or implementing performance-critical operations that benefit from direct libc calls. It's employed in gems that need fine-grained control over system resources, require specific libc behavior, or wrap C libraries that expect libc data structures. While most Ruby applications don't need direct libc access, the gem fills a niche for systems programming, performance optimization, and scenarios requiring precise control over memory or system operations that Ruby abstracts away.

gdk_pixbuf2

gdk_pixbuf2 provides Ruby bindings to GdkPixbuf, the GNOME image loading and manipulation library supporting multiple image formats. GdkPixbuf handles loading, saving, and basic manipulation of images including PNG, JPEG, GIF, TIFF, and other formats through a plugin system. The gem brings GdkPixbuf's capabilities to Ruby, enabling image processing in GTK applications or standalone image manipulation tasks. The library supports loading images from files, memory buffers, or streams, with automatic format detection and error handling. It provides operations for scaling, rotating, compositing, and applying basic transformations to images efficiently. gdk_pixbuf2 includes support for animated images (like animated GIFs), ICC color profile handling, and thumbnail generation. The gem integrates with GTK's drawing system for displaying images in GUI applications and supports saving images with format-specific options. Built on glib2, it inherits GLib's object system and memory management patterns. gdk_pixbuf2 is used in Ruby GTK applications requiring image display or manipulation, thumbnail generators, image conversion tools, and applications needing cross-platform image format support without heavy dependencies. It's particularly valuable for Linux desktop applications, system utilities displaying icons or images, and scripts processing images as part of larger GTK-based workflows. While other gems like rmagick or mini_magick offer more extensive image processing features, gdk_pixbuf2 excels in scenarios where GTK integration is needed or where GdkPixbuf's format support and lightweight footprint are sufficient.