Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
If object is an Integer object, returns object.
Integer.try_convert(1) # => 1
Otherwise if object responds to :to_int, calls object.to_int and returns the result.
Integer.try_convert(1.25) # => 1
Returns nil if object does not respond to :to_int
Integer.try_convert([]) # => nil
Raises an exception unless object.to_int returns an Integer object.
 
               # File numeric.rb, line 247
def Integer.try_convert(num)
=begin
  Primitive.attr! 'inline'
  Primitive.cexpr! 'rb_check_integer_type(num)'
=end
end
            

Was this page useful?