Accessing Ruby at elk01:
#!/usr/bin/rubyThen you have to make the file pi.rb executable, using the command % chmod +x pi.rb, and you can invoke Ruby to run the program by just typing its name: pi.rb, at the Unix % prompt. So now download pi.rb, make it executable, and execute it, by typing ./pi.rb when the file is in your current directory. (This is the way the elk01 system and my Linux system at home are set up: You have to type ./xyz to execute a file xyz in the current directory.) Downloading Ruby to Your Home Machine:
Online Ruby Through a Browser:
Ruby in debug mode: Ruby has a fancy debug mode available:
Options for debug mode are give at: Debug Options. % ruby -r debug pi2.rb Debug.rb Emacs support available. pi.rb:2:k, a, b, a1, b1 = 2, 4, 1, 12, 4 (rdb:1) list 1-13 [1, 13] in pi.rb 1 => 2 k, a, b, a1, b1 = 2, 4, 1, 12, 4 3 loop do 4 p, q, k = k*k, 2*k+1, k+1 5 a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1 6 d, d1 = a/b, a1/b1 7 while d == d1 8 print d 9 $stdout.flush 10 a, a1 = 10*(a%b), 10*(a1%b1) 11 d, d1 = a/b, a1/b1 12 end 13 end (rdb:1) b 4 Set breakpoint 1 at pi.rb:4 (rdb:1) c Breakpoint 1, toplevel at pi.rb:4 pi.rb:4: p, q, k = k*k, 2*k+1, k+1 (rdb:1) c 3Breakpoint 1, toplevel at pi.rb:4 pi.rb:4: p, q, k = k*k, 2*k+1, k+1 (rdb:1) c 1Breakpoint 1, toplevel at pi.rb:4 pi.rb:4: p, q, k = k*k, 2*k+1, k+1 (rdb:1) c Breakpoint 1, toplevel at pi.rb:4 pi.rb:4: p, q, k = k*k, 2*k+1, k+1 (rdb:1) c 4Breakpoint 1, toplevel at pi.rb:4 pi.rb:4: p, q, k = k*k, 2*k+1, k+1 (rdb:1) c 1Breakpoint 1, toplevel at pi.rb:4 pi.rb:4: p, q, k = k*k, 2*k+1, k+1 (rdb:1) exit %Notice that as this program runs, after repeated c or cont commands (for "continue execution"), the program loops over and over to the breakpoint that was set at line 4. As it executes, it is outputting the initial digits of pi, shown in red above. Here are 14 of the 33 commands given at the link above. You need not use the complete command name, but the part given inside [...] is optional.
Revision date: 2013-11-05. (Please use ISO 8601, the International Standard Date and Time Notation.) |