Changes in Modules and Classes

 
   

Ruby Way
By Hal Fulton
Slots : 1.0
Table of Contents
 


The classes and modules are naturally where the bulk of the changes lie. Some have had methods added; others have merely had method semantics shift a little. This list is mostly alphabetical by class or module name; the exception is at the bottom of the list where we've put all the miscellaneous items.

The methods named here are instance methods, unless noted as class methods.

Class Array

  • fetch added.

  • insert added. The new method arr.insert(n, x, y, z) acts just like arr[n,0] = [x,y,z], but returns self rather than the assigned value.

  • sort! always returns self without checking for modification of the array's contents. This behavior may change and should not be relied on.

Class Dir

  • Dir.chdir has been extended to take a block. Like such methods as File.open, the operation is only in effect within the scope of the block.

  • Dir.glob now supports metacharacters escaped by a backslash; wildcards and spaces may now be escaped at will.

  • Dir.open now returns the block return value like File.open, not nil as in Ruby 1.6.

  • Dir.chdir will warn only when it is invoked from multiple threads or when no block is specified.

Module Enumerable

  • all? added (detects whether all items fit a given criterion).

  • any? added (detects whether any item fits the given criterion).

  • inject added (analogous to Smalltalk's inject).

  • sort_by added (sorts by specified field or key).

Class File

  • fnmatch added (along with constants File::Constants::FNM_*). See documentation for the Unix utility fnmatch.

  • File.lchmod and File.lchown added (for symbolic links).

Class IO

  • IO.for_fd added.

  • IO.read added (see ruby-talk:9460).

Module Math

  • Math.acos(x) added.

  • Math.asin(x) added.

  • Math.atan(x) added.

  • Math.cosh(x) added.

  • Math.hypot(x,y) added.

  • Math.sinh(x) added.

  • Math.tanh(x) added.

Class Module

  • include? added.

  • included added. This is a hook called after Module#append_feature.

  • method_removed added.

  • method_undefined added.

Class Object

  • singleton_method_removed hook added.

  • singleton_method_undefined hook added.

Class Proc

  • == added.

  • yield added. This is like call except that it doesn't check the number of arguments; the arguments are thus passed in as they are.

Class Process

  • Process.times has been moved from Time.times. (The latter is still there but gives a warning.)

  • Process.waitall added.

  • The Process::Status class has been added. $? is now an instance of this class.

Class Range

  • step added (default is 1).

  • to_ary added. It's now possible to use a construct such as a, b, c = 1..3 without using to_a.

Class Regexp

  • It's no longer legal to regard a standalone /re/ as meaning /re/ =~ $_ in a conditional. You must explicitly use the match operator ~ instead.

  • options added.

  • Regexp.last_match has been extended to take an optional argument.

Class String=

  • casecmp added (case-insensitive comparison).

  • eql? has been changed to be always case sensitive.

  • insert added; the method call str.insert(n, s2) acts like str[n, 0] = s2, but returns itself rather than the value of the assignment.

  • lstrip, rstrip, lstrip!, and rstrip! have been added to strip only the left or right sides of a string, respectively.

Class Symbol

  • intern added.

  • Symbol.all_symbols added.

Class Time

  • The Time can now handle a negative time_t (when the platform supports it). This extends the range of dates back into the year 1901.

  • to_a added.

  • zone Now returns "UTC" under gmtime.

Other Classes and Modules

  • Interrupt is now a subclass of SignalException, rather than Exception.

  • Kernel.open has been extended so that when the third argument is a set of permission flags, the underlying call will be open(2), rather than fopen(3).

  • Marshal will no longer dump anonymous classes/modules.

  • The Regexp class has to_ary added for convenience in using the match method on the right-hand side in a multiple assignment. Previously, you had to say something like junk, m1, m2, m3 = regex.match(str).to_a, whereas now you can say junk, m1, m2, m3 = regex.match(str) (omitting the to_a).

  • Method#== added.

  • NameError and NoMethodError have moved; now NoMethodError is a subclass of NameError, which in turn is a subclass of StandardError.

  • NotImplementError is obsolete because of its "broken English." Use NotImplementedError instead.

  • A new module Signal has been added; it has the module functions Signal::trap and Signal::list.

  • SystemCallError.=== added. Refer to the note on comparison of exception classes in the rescue clause (at the top of this appendix).

  • SystemExit#status added.


   

 

 



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

Similar book on Amazon

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