您的位置:首页 > 编程语言 > Ruby

More About Methods(Chapter 8 of Programming Ruby)

2010-06-29 00:05 801 查看
  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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: