Ruby

23
1162 reads

March 4, 2013

String Reverse


This shows that when you use the reverse method, for example, no change is made to the ‘receiver object’ (that is, an object such as str1 here: str1.reverse). But when you use the reverse!

36
1223 reads

March 4, 2013

Breaking Encapsulation


Here we have a method called stringProcess which takes two string arguments, messes about with them and returns the results.

26
1235 reads

March 4, 2013

Using Each Loop


To convert the for loop to an each iterator, all we had to do is delete for and in and append .each to the array. Then we have to put the iterator variable, i, between a pair of upright bars after do.

40
1227 reads

March 4, 2013

Returning Values


In many programming languages, a distinction is made between functions or methods which return a value to the calling code and those which do not.

39
1313 reads

March 4, 2013

Returning Multiple Values


But what about those occasions when you need a method to return more than one value?

21
1234 reads

March 4, 2013

Parentheses Avoid Ambiguity


Methods may share the same name as a local variable. For example, you might have a variable called name and a method called name.

34
1167 reads

March 4, 2013

Parallel Assignment


it is possible for a method to return multiple values, separated by commas. Often you will want to assign these returned values to a set of matching variables.

23
1375 reads

March 4, 2013

Blocks


Ruby has an alternative syntax for delimiting blocks. Instead of using do..end, you can use curly braces {..}

27
1215 reads

March 4, 2013

Integer Object ID's


In Ruby an integer (Fixnum) has a fixed identity. Every instance of the number 10 or every variable to which the value 10 is assigned will have the same ob-ject_id.

25
1174 reads

March 4, 2013

Information NotHidding2


Information is not hidden and can be used anywhere in the program.