Changes in Syntax and General Behavior

 
   

Ruby Way
By Hal Fulton
Slots : 1.0
Table of Contents
 


The syntax of Ruby is its most stable aspect, but it still evolves over time, with allowances made for backward compatibility. We've summarized some recent changes here, including one that is experimental.

  • Multiple assignment behavior has changed. The assignment *a = nil will now make the conditional a == [] true.

  • Array expansion: If you assign a = *[1], you now find that a is 1 (rather than [1] as before).

  • Experimental: break and next can now take an optional expression used as a value for termination.

  • to_str support has been added. Now almost all built-in methods which expect a String will call the object's to_str method if it is not a String. For example, any object with a to_str method can be meaningfully passed into File.open without manually calling to_s or any similar trick.

  • Comparison of exception classes in a rescue clause has changed slightly. Now Module#=== (rather than kind_of?) is used for the comparison. In conjunction with this, SystemCallError#=== now returns true for identical errno values. In practice, this means that when multiple SystemCallErrors have the same errno, any one of them can be specified in the rescue clause and they will all be caught.


   

 

 



The Ruby Way
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2000
Pages: 119
Authors: Hal Fulton

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net