lib/polyfill/internal_utils.rb in polyfill-1.2.0 vs lib/polyfill/internal_utils.rb in polyfill-1.3.0
- old
+ new
@@ -1,7 +1,7 @@
module Polyfill
- module InternalUtils
+ module InternalUtils # rubocop:disable Metrics/ModuleLength
VERSIONS = {
'2.2' => 'V2_2',
'2.3' => 'V2_3',
'2.4' => 'V2_4',
'2.5' => 'V2_5'
@@ -90,32 +90,57 @@
Polyfill::Module.const_set("M#{mod.object_id}", mod)
end
module_function :create_module
def to_str(obj)
- unless obj.respond_to?(:to_str)
- raise TypeError, "no implicit conversion of #{obj.class} into String"
+ begin
+ unless obj.respond_to?(:to_str)
+ raise TypeError, "no implicit conversion of #{obj.class} into String"
+ end
+ rescue NoMethodError
+ raise TypeError, 'no implicit conversion of BasicObject into String'
end
obj.to_str
end
module_function :to_str
def to_int(obj)
- unless obj.respond_to?(:to_int)
- raise TypeError, "no implicit conversion of #{obj.class} into Integer"
+ begin
+ unless obj.respond_to?(:to_int)
+ raise TypeError, "no implicit conversion of #{obj.class} into Integer"
+ end
+ rescue NoMethodError
+ raise TypeError, 'no implicit conversion of BasicObject into Integer'
end
obj.to_int
end
module_function :to_int
def to_f(obj)
- unless obj.respond_to?(:to_f)
- raise TypeError, "no implicit conversion of #{obj.class} into Float"
+ begin
+ unless obj.respond_to?(:to_f)
+ raise TypeError, "no implicit conversion of #{obj.class} into Float"
+ end
+ rescue NoMethodError
+ raise TypeError, 'no implicit conversion of BasicObject into Float'
end
obj.to_f
end
module_function :to_f
+
+ def to_hash(obj)
+ begin
+ unless obj.respond_to?(:to_hash)
+ raise TypeError, "no implicit conversion of #{obj.class} into Hash"
+ end
+ rescue NoMethodError
+ raise TypeError, 'no implicit conversion of BasicObject into Hash'
+ end
+
+ obj.to_hash
+ end
+ module_function :to_hash
end
end