talira

Classes and mixins that make Ruby hashes more powerful

open sourceMITfree

Hashie is a Ruby gem with a growing collection of tools that extend hashes. Mash adds method-style access to keys and wraps nested hashes; Dash accepts only declared properties, with defaults and required properties; Trash is a Dash that translates keys; Clash builds hashes by chaining methods; Rash maps keys that are regexps or ranges to values. Mixins add coercion (including with dry-types or ActiveModel), key conversion, indifferent access, deep merge, deep fetch and find, and strict key access to any Hash subclass. It was started at Intridea and is maintained by the hashie project.

Problems it solves

  • access nested Ruby hash keys like methods
  • define a Ruby hash that only accepts known properties with defaults
  • coerce values in a Ruby hash to the right types

Features

  • Mash: method-style access to hash keys, wrapping nested hashes
  • Dash: hashes with declared, defaulted and required properties
  • Trash: a Dash that translates keys on initialization
  • Clash: chainable lazy hash for building option hashes
  • Rash: hashes whose keys are regexps or ranges
  • Mixins for coercion, key conversion, indifferent access, deep merge, deep fetch and strict key access