Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/friendfeed/compat.rb

Overview

-*- mode:ruby -*- – friendfeed/compat.rb - defines compatibility methods for older Ruby ++ Copyright © 2009, 2010 Akinori MUSHA <[email protected]>

All rights reserved. You can redistribute and/or modify it under the same terms as Ruby.

Class Method Summary collapse

Class Method Details

.try_convert(obj) ⇒ Object

Raises:

  • (TypeError)


12
13
14
15
16
17
18
# File 'lib/friendfeed/compat.rb', line 12

def self.try_convert(obj)
  return obj if obj.instance_of?(self)
  return nil if !obj.respond_to?(:to_hash)
  nobj = obj.to_hash 
  return nobj if nobj.instance_of?(self)
  raise TypeError, format("can't convert %s to %s (%s#to_hash gives %s)", obj.class, self.class, obj.class, nobj.class)
end