On ruby-talk somebody was asking for a method which will be used to generate a random string, by returning either a lowercase letter or one of the digits 0-9 when called. As an example he posted the following Pascal program:
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
<span class='line'><span class="k">function</span> <span class="nf">GetRandomChar</span><span class="o">:</span> <span class="kt">char</span><span class="o">;</span>
</span><span class='line'><span class="k">var</span>
</span><span class='line'> <span class="n">r</span><span class="o">:</span> <span class="kt">integer</span><span class="o">;</span>
</span><span class='line'><span class="k">begin</span>
</span><span class='line'> <span class="n">r</span> <span class="o">:=</span> <span class="nb">random</span><span class="p">(</span><span class="mi">36</span><span class="p">)</span><span class="o">;</span>
</span><span class='line'> <span class="k">case</span> <span class="n">r</span> <span class="k">of</span>
</span><span class='line'> <span class="mi">0</span><span class="o">..</span><span class="mi">25</span><span class="o">:</span> <span class="bp">result</span> <span class="o">:=</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">ord</span><span class="p">(</span><span class="s">'a'</span><span class="p">)</span> <span class="o">+</span> <span class="n">r</span><span class="p">)</span><span class="o">;</span>
</span><span class='line'> <span class="k">else</span> <span class="o">:</span> <span class="bp">result</span> <span class="o">:=</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">ord</span><span class="p">(</span><span class="s">'0'</span><span class="p">)</span> <span class="o">+</span> <span class="n">r</span><span class="p">)</span><span class="o">;</span>
</span><span class='line'> <span class="k">end</span><span class="o">;</span>
</span><span class='line'><span class="k">end</span><span class="o">;</span>
</span>
“Translating” this to Ruby, this is what I got:
In your face, Niklaus Wirth! ;-)
P.S. Actually I do have fond memories of the good old Turbo Pascal days.