Sha256: f941049dd34d98b8599911d0cf67ef0d3d94dab8da56f7081db1e24b9f1dbf6a

Contents?: true

Size: 401 Bytes

Versions: 12

Compression:

Stored size: 401 Bytes

Contents

# frozen_string_literal: true

RubyNext::Core.patch Integer.singleton_class, method: :try_convert, singleton: Integer, version: "3.1" do
  <<-'RUBY'
def try_convert(val)
  return val if val.is_a?(Integer)

  if val.respond_to?(:to_int)
    val.to_int.tap do |res|
      next if res.is_a?(Integer) || res.nil?
      raise TypeError, "Can't convert #{res.class} to Integer"
    end
  end
end
  RUBY
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ruby-next-core-1.1.0 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-1.0.3 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-1.0.2 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-1.0.1 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-1.0.0 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-1.0.0.rc.1 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-0.15.3 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-0.15.2 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-0.15.1 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-0.15.0 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-0.14.1 lib/ruby-next/core/integer/try_convert.rb
ruby-next-core-0.14.0 lib/ruby-next/core/integer/try_convert.rb