Ruby

359
4680 reads

January 24, 2013

Array Declaration


The code shows how to declare a new array.

22
1181 reads

January 24, 2013

Compare arrays using <=>


Two arrays are considered equal if they are of the same length and if the value of each element is equal to the value of the corresponding element in the other array.

176
1989 reads

January 24, 2013

Comparing Arrays


Two arrays are considered equal if
(1) they contain the same number of elements, and
(2) each element is equal to the corresponding element in the other array.

62
1269 reads

January 23, 2013

Variable Arguments


Variable number of arguments are passed to a method just by prefixing an argument with a splat (*). The variable list of arguments always comes at the end of the argument list.

300
4327 reads

January 23, 2013

Default Arguments


This code shows how "default arguments" come into play when no arguments are passed to a function with parameters.

33
1263 reads

January 23, 2013

delete and delete! methods


The delete! method which end in '!', it makes changes in place to an object rather than
to a copy.It changes the object itself.

24
1214 reads

January 23, 2013

Method returning BOOLEAN


When a method name ends with a question mark (?), as in eql?, then the method returns
a Boolean—true or false.

396
5474 reads

January 23, 2013

Inserting a String in a String


The insert method lets you insert another string at a given index in a string.

315
4014 reads

January 23, 2013

gsub method


This method replaces a substring (first argument) with a replacement
string (second argument).

76
1268 reads

January 23, 2013

Ternary Operator


This code demonstrates how to use ternary operator in ruby.