Module: FlexibleHashAccess

Defined in:
lib/familia/refinements.rb

Overview

FlexibleHashAccess

This module provides a refinement for the Hash class to allow flexible access to hash keys using either strings or symbols interchangeably for reading values.

Note: This refinement only affects reading from the hash. Writing to the hash maintains the original key type.

Examples:

Using the refinement

using FlexibleHashAccess

h = { name: "Alice", "age" => 30 }
h[:name]   # => "Alice"
h["name"]  # => "Alice"
h[:age]    # => 30
h["age"]   # => 30

h["job"] = "Developer"
h[:job]    # => "Developer"
h["job"]   # => "Developer"

h[:salary] = 75000
h[:salary] # => 75000
h["salary"] # => nil (original key type is preserved)