This is a Ruby tree! It shows every object from the Ruby Programming Language in a tree format.

to_r

        # String.to_r

(from ruby core)
---
    str.to_r  ->  rational

---

Returns the result of interpreting leading characters in `str` as a
rational.  Leading whitespace and extraneous characters past the end of
a valid number are ignored. Digit sequences can be separated by an
underscore. If there is not a valid number at the start of `str`, zero
is returned.  This method never raises an exception.

    '  2  '.to_r       #=> (2/1)
    '300/2'.to_r       #=> (150/1)
    '-9.2'.to_r        #=> (-46/5)
    '-9.2e2'.to_r      #=> (-920/1)
    '1_234_567'.to_r   #=> (1234567/1)
    '21 June 09'.to_r  #=> (21/1)
    '21/06/09'.to_r    #=> (7/2)
    'BWV 1079'.to_r    #=> (0/1)

NOTE: "0.3".to_r isn't the same as 0.3.to_r.  The former is equivalent
to "3/10".to_r, but the latter isn't so.

    "0.3".to_r == 3/10r  #=> true
    0.3.to_r   == 3/10r  #=> false

See also Kernel#Rational.



      

This is MURDOC! A Ruby documentation browser inspired by Smalltalk-80. It allows you to learn about Ruby by browsing through its class hierarchies, and see any of its methods.