The Ruby way. vs. The Python way
Here are a the python examples of the Active Python Python tutorial and their Ruby counterpart. By comparing simple operations the strength of both languages come to show.
When you instruct the script to read an integer from STDIN.
In python:
>>> x = int(raw_input("please enter an interger: "))in Ruby:
irb(main):041:0> p "please enter an integer: " "please enter an integer: " => nil irb(main):042:0> x = gets.to_iIn Ruby there is no raw_input equivalent. In Python the int() operation converts the input string to integer while in Ruby the string object returned by gets invokes the to_i method to convert the string to an integer. Interesting.
Comments