正文

ruby learning2007-03-12 15:07:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/daweizhao/23870.html

分享到:

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.

 

 

阅读(1894) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册