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!
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!
Here we have a method called stringProcess which takes two string arguments, messes about with them and returns the results.
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.
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.
But what about those occasions when you need a method to return more than one value?
Methods may share the same name as a local variable. For example, you might have a variable called name and a method called name.
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.
Ruby has an alternative syntax for delimiting blocks. Instead of using do..end, you can use curly braces {..}
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.