Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/authy/core_ext.rb

Direct Known Subclasses

Authy::Response

Class Method Summary collapse

Class Method Details

.try_convert(value) ⇒ Object

Raises:

  • (TypeError)


2
3
4
5
6
7
8
9
10
11
# File 'lib/authy/core_ext.rb', line 2

def self.try_convert(value)
  return value if value.instance_of?(Hash)
  return nil if !value.respond_to?(:to_hash)
  converted = value.to_hash
  return converted if converted.instance_of?(Hash)

  cname = value.class.name
  raise TypeError, "can't convert %s to %s (%s#%s gives %s)" %
    [cname, Hash.name, cname, :to_hash, converted.class.name]
end