Module: IndiferentHash

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

Overview

TODO: REMOVE class RBBTError < StandardError

attr_accessor :info

alias old_to_s to_s
def to_s
  str = old_to_s.dup
  if info
    str << "\n" << "Additional Info:\n---\n" << info << "---"
  end
  str
end

end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup(hash) ⇒ Object



1397
1398
1399
# File 'lib/rbbt/util/misc.rb', line 1397

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

Instance Method Details

#[](key) ⇒ Object



1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
# File 'lib/rbbt/util/misc.rb', line 1401

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



1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
# File 'lib/rbbt/util/misc.rb', line 1429

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)


1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
# File 'lib/rbbt/util/misc.rb', line 1418

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



1414
1415
1416
# File 'lib/rbbt/util/misc.rb', line 1414

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