HashWithIndifferentAccess に変換して実現する

環境

  • rails: rails 6.0.3.6

実際のコード

rgb = { black: '#0000', white: '#FFFFFF' }.with_indifferent_access

rgb[:black]   # => "#0000"
rgb['black']  # => "#0000"
rgb[:'black'] # => "#0000"
rgb[:white]   # => "#FFFFFF"
rgb['white']  # => "#FFFFFF"
rgb[:'white'] # => "#FFFFFF"