lib/polyfill/internal_utils.rb in polyfill-1.0.1 vs lib/polyfill/internal_utils.rb in polyfill-1.1.0

- old
+ new

@@ -1,11 +1,12 @@ module Polyfill module InternalUtils VERSIONS = { '2.2' => 'V2_2', '2.3' => 'V2_3', - '2.4' => 'V2_4' + '2.4' => 'V2_4', + '2.5' => 'V2_5' }.freeze private_constant :VERSIONS def current_ruby_version @current_ruby_version ||= RUBY_VERSION[/\A(\d+\.\d+)/, 1] @@ -87,7 +88,25 @@ yield(mod) 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" + 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" + end + + obj.to_int + end + module_function :to_int end end