Ruby

359
4668 reads

January 24, 2013

Array Declaration


The code shows how to declare a new array.

22
1170 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
1976 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
1252 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
4311 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
1247 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
1198 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
5458 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
3996 reads

January 23, 2013

gsub method


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

76
1252 reads

January 23, 2013

Ternary Operator


This code demonstrates how to use ternary operator in ruby.