Ray's playground

 

More About Methods(Chapter 8 of Programming Ruby)

  Methods that return a boolean result (socalled predicate methods) are often named with a trailing ?.

  Methods that are “dangerous,” or that modify their receiver, may be named with a trailing exclamation mark, !. These are sometimes called bang methods. 

  Methods that can appear on the left side of an assignment end with an equals sign (=). 

  But what if you want to pass in a variable number of arguments or want to capture multiple arguments into a single parameter? Placing an asterisk before the name of the parameter after the “normal” parameters lets you do just that. This is sometimes called splatting an argument.

  However, if the last parameter in a method definition is prefixed with an ampersand, any associated block is converted to a Proc object, and that object is assigned to the parameter. This allows you to store the block for use later. 

 

 

posted on 2010-06-29 00:05  Ray Z  阅读(181)  评论(0编辑  收藏  举报

导航