Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
insensitive_hash_bxf
Advanced tools
Hash with case-insensitive, Symbol/String-indifferent key access.
This project is a fork from https://github.com/junegunn/insensitive_hash and it was made to continue its maintenance.
gem install insensitive_hash_bxf
require 'insensitive_hash'
ih = {}.insensitive
ih = { :abc => 1, 'hello world' => true }.insensitive
ih['ABC'] # 1
ih[:Hello_World] # true
If you don't like to have Hash#insensitive method, require 'insensitive_hash/minimal'
require 'insensitive_hash/minimal'
ih = InsensitiveHash.new
ih = InsensitiveHash.new(:default_value)
ih = InsensitiveHash.new { |ih, k| ih[k] = InsensitiveHash.new }
ih = InsensitiveHash[ 'abc' => 1, :def => 2 ]
ih = InsensitiveHash[ 'abc', 1, :def, 2 ]
ih = InsensitiveHash[ [['abc', 1], [:def, 2]] ]
ih = InsensitiveHash[ 'hello world' => true ]
h = ih.sensitive
h = ih.to_hash
ih = {:abc => 1, 'DEF' => 2}.insensitive
# Case-insensitive, Symbol/String-indifferent access.
ih['Abc'] # 1
ih[:ABC] # 1
ih['abc'] # 1
ih[:abc] # 1
ih.has_key?(:DeF) # true
ih['ABC'] = 10
# keys and values
ih.keys # ['DEF', 'ABC']
ih.values # [2, 10]
# delete
ih.delete :Abc # 10
ih.keys # ['DEF']
When an InsensitiveHash is built from another Hash, descendant Hash values are recursively converted to be insensitive.
ih = { 'kids' => { :hello => [ { :world => '!!!' } ] } }.insensitive
ih[:kids]['Hello'].first['WORLD'] # !!!
ih = {:one => [ [ [ { :a => { :b => { :c => 'd' } } } ] ] ]}.insensitive
ih['one'].first.first.first['A']['b'][:C] # 'd'
However, once InsensitiveHash is initialized, descendant Hashes (or Hashes in Arrays) are not automatically converted.
ih = {}.insensitive
ih[:abc] = { :def => true }
ih['ABC']['DEF'] # nil
Simply build a new InsensitiveHash out of it if you need recursive conversion.
ih2 = ih.insensitive
ih2['ABC']['DEF'] # true
db = YAML.load(File.read 'database.yml').insensitive
# Access values however you like
db['Development']['ADAPTER']
db[:production][:adapter]
ih = InsensitiveHash.new
ih.safe = true
# Will raise InsensitiveHash::KeyClashError
h.merge!('hello world' => 1, :hello_world => 2)
# Disables key-clash detection
h.safe = false
h.merge!('hello world' => 1, :hello_world => 2)
h['Hello World'] # 2
See LICENSE.txt for further details.
FAQs
Unknown package
We found that insensitive_hash_bxf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.