method
to_r
v1_9_2_180 -
Show latest stable
-
0 notes -
Class: String
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378 (0)
- 1_9_2_180 (38)
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (1)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (12)
- 2_6_3 (0)
- What's this?
to_r()
public
Returns a rational which denotes the string form. The parser ignores leading whitespaces and trailing garbage. Any digit sequences can be separated by an underscore. Returns zero for null or garbage string.
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.
For example:
' 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)