Module: IndiferentHash

Defined in:
lib/rbbt/util/misc.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup(hash) ⇒ Object



1360
1361
1362
# File 'lib/rbbt/util/misc.rb', line 1360

def self.setup(hash)
  hash.extend IndiferentHash 
end

Instance Method Details

#[](key) ⇒ Object



1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
# File 'lib/rbbt/util/misc.rb', line 1364

def [](key)
  res = super(key) and return res

  case key
  when Symbol, Module
    super(key.to_s)
  when String
    super(key.to_sym)
  else
    super(key)
  end
end

#delete(key) ⇒ Object



1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
# File 'lib/rbbt/util/misc.rb', line 1392

def delete(key)
  case key
  when Symbol, Module
    super(key) || super(key.to_s)
  when String
    super(key) || super(key.to_sym)
  else
    super(key)
  end
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
# File 'lib/rbbt/util/misc.rb', line 1381

def include?(key)
  case key
  when Symbol, Module
    super(key) || super(key.to_s)
  when String
    super(key) || super(key.to_sym)
  else
    super(key)
  end
end

#values_at(*key_list) ⇒ Object



1377
1378
1379
# File 'lib/rbbt/util/misc.rb', line 1377

def values_at(*key_list)
  key_list.inject([]){|acc,key| acc << self[key]}
end