Ruby (programming language): Difference between revisions

Content deleted Content added
m sp
Improve code example, fix version
Line 24:
 
The language was created by [[Yukihiro Matsumoto]] on February 24, 1993. The
current stable version is 1.6.6 (26-12-2001)7. Note that the name is not an
[[acronym]]--it is actually a [[pun]] on [[Perl]]. According to the author, he
designed Ruby to follow the ''principle of least surprise'' (POTS), meaning that the
language should be free from the traps and inconsistencies that plague other
languages.
Line 33:
 
<pre>
# Execute the following block of code 10 times
string1 = "Hello world" # assign "Hello world" string to variable 'string1'
10.times {
string2 = string1.gsub(" ", ", ") # replace all " " by ", " in 'string1', put result into variable 'string2'
string1 = "Hello world".gsub(" ", ",") # Replace ' ' with ', ' and store in string1
string2 += "!\n" # append "!\n" ("\n" is newline character) to variable 'string2'
print string2 string1 += "!" # printappend "!" to variable 'string2string1'
puts string1 # print variable 'string1', followed by a newline
}
</pre>