Methods are invoked by sending a message to an object. The message contains the method's name, along with any parameters the method may need. When an object receives a message, it looks into its own calss for a corresponding method. if found, that method is executed. If the method isn't found.... This business of methods and message may sound complicated, but in practive it is very natural. Let's look at some method calls: "gin goint".length --> 9; "Rick".index("c" ) --> 2; -1942.abc --> 1942
It's worth noting here a major difference between Ruby and most other languages. In Java, you'd find the absolute value of some number by calling a separate function and passing in that number: number = Math.abs(nmmber) //JAVA number = number.abs //ruby In ruby, the ability to determine an absolute value is built into numbers __ they take care of the details internally.
评论