Ruby (programming language): Difference between revisions

Content deleted Content added
JackH (talk | contribs)
Subtitle added
JackH (talk | contribs)
Some more examples added (taken from the German version)
Line 33:
 
== Examples ==
Here is asome sampleexsamples of Ruby code:
 
 
>> -199.abs # Die number 199 is an object; the method ''abs'' is called.
=> 199
 
>> "Ruby is cool".length # ''length'' is a method of String objects
=> 13
 
>> "Rick".index("c")
=> 2
 
>> "John".swapcase
=> "jOHN"
 
 
>> #Arrays
?> [11, 5, 7, 2, 13, 3].sort
=> [2, 3, 5, 7, 11, 13]
 
>> [11, 5, 7, 2, 13, 3].sort.reverse
=> [13, 11, 7, 5, 3, 2]
 
 
# Execute the following block of code 10 times