Raised when OLE processing failed.
EX:
obj = WIN32OLE.new("NonExistProgID")
raises the exception:
WIN32OLERuntimeError: unknown OLE server: `NonExistProgID' HRESULT error code:0x800401f3 Invalid class string
Use the Monitor
class when you want to have a lock object for blocks with mutual exclusion.
require 'monitor' lock = Monitor.new lock.synchronize do # exclusive access end
Raised when attempting to divide an integer by 0.
42 / 0 #=> ZeroDivisionError: divided by 0
Note that only division by an exact 0 will raise the exception:
42 / 0.0 #=> Float::INFINITY 42 / -0.0 #=> -Float::INFINITY 0 / 0.0 #=> NaN
The Comparable
mixin is used by classes whose objects may be ordered. The class must define the <=>
operator, which compares the receiver against another object, returning -1, 0, or +1 depending on whether the receiver is less than, equal to, or greater than the other object. If the other object is not comparable then the <=>
operator should return nil. Comparable
uses <=>
to implement the conventional comparison operators (<
, <=
, ==
, >=
, and >
) and the method between?
.
class SizeMatters include Comparable attr :str def <=>(other) str.size <=> other.str.size end def initialize(str) @str = str end def inspect @str end end s1 = SizeMatters.new("Z") s2 = SizeMatters.new("YY") s3 = SizeMatters.new("XXX") s4 = SizeMatters.new("WWWW") s5 = SizeMatters.new("VVVVV") s1 < s2 #=> true s4.between?(s1, s3) #=> false s4.between?(s3, s5) #=> true [ s3, s2, s5, s4, s1 ].sort #=> [Z, YY, XXX, WWWW, VVVVV]
Copyright © 2000-2007 Minero Aoki
This program is free software. You can distribute/modify this program under the same terms of ruby.
FileUtils
Namespace for several file utility methods for copying, moving, removing, etc.
Module
Functions require 'fileutils' FileUtils.cd(dir, options) FileUtils.cd(dir, options) {|dir| block } FileUtils.pwd() FileUtils.mkdir(dir, options) FileUtils.mkdir(list, options) FileUtils.mkdir_p(dir, options) FileUtils.mkdir_p(list, options) FileUtils.rmdir(dir, options) FileUtils.rmdir(list, options) FileUtils.ln(target, link, options) FileUtils.ln(targets, dir, options) FileUtils.ln_s(target, link, options) FileUtils.ln_s(targets, dir, options) FileUtils.ln_sf(target, link, options) FileUtils.cp(src, dest, options) FileUtils.cp(list, dir, options) FileUtils.cp_r(src, dest, options) FileUtils.cp_r(list, dir, options) FileUtils.mv(src, dest, options) FileUtils.mv(list, dir, options) FileUtils.rm(list, options) FileUtils.rm_r(list, options) FileUtils.rm_rf(list, options) FileUtils.install(src, dest, options) FileUtils.chmod(mode, list, options) FileUtils.chmod_R(mode, list, options) FileUtils.chown(user, group, list, options) FileUtils.chown_R(user, group, list, options) FileUtils.touch(list, options)
The options
parameter is a hash of options, taken from the list :force
, :noop
, :preserve
, and :verbose
. :noop
means that no changes are made. The other three are obvious. Each method documents the options that it honours.
All methods that have the concept of a “source” file or directory can take either one file or a list of files in that argument. See the method documentation for examples.
There are some ‘low level’ methods, which do not accept any option:
FileUtils.copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false) FileUtils.copy_file(src, dest, preserve = false, dereference = true) FileUtils.copy_stream(srcstream, deststream) FileUtils.remove_entry(path, force = false) FileUtils.remove_entry_secure(path, force = false) FileUtils.remove_file(path, force = false) FileUtils.compare_file(path_a, path_b) FileUtils.compare_stream(stream_a, stream_b) FileUtils.uptodate?(file, cmp_list)
FileUtils::Verbose
This module has all methods of FileUtils
module, but it outputs messages before acting. This equates to passing the :verbose
flag to methods in FileUtils
.
FileUtils::NoWrite
This module has all methods of FileUtils
module, but never changes files/directories. This equates to passing the :noop
flag to methods in FileUtils
.
FileUtils::DryRun
This module has all methods of FileUtils
module, but never changes files/directories. This equates to passing the :noop
and :verbose
flags to methods in FileUtils
.
In concurrent programming, a monitor is an object or module intended to be used safely by more than one thread. The defining characteristic of a monitor is that its methods are executed with mutual exclusion. That is, at each point in time, at most one thread may be executing any of its methods. This mutual exclusion greatly simplifies reasoning about the implementation of monitors compared to reasoning about parallel code that updates a data structure.
You can read more about the general principles on the Wikipedia page for Monitors
require 'monitor.rb' buf = [] buf.extend(MonitorMixin) empty_cond = buf.new_cond # consumer Thread.start do loop do buf.synchronize do empty_cond.wait_while { buf.empty? } print buf.shift end end end # producer while line = ARGF.gets buf.synchronize do buf.push(line) empty_cond.signal end end
The consumer thread waits for the producer thread to push a line to buf while buf.empty?
. The producer thread (main thread) reads a line from ARGF
and pushes it into buf then calls empty_cond.signal
to notify the consumer thread of new data.
Class
include require 'monitor' class SynchronizedArray < Array include MonitorMixin def initialize(*args) super(*args) end alias :old_shift :shift alias :old_unshift :unshift def shift(n=1) self.synchronize do self.old_shift(n) end end def unshift(item) self.synchronize do self.old_unshift(item) end end # other methods ... end
SynchronizedArray
implements an Array
with synchronized access to items. This Class
is implemented as subclass of Array
which includes the MonitorMixin
module.
Timeout
long-running blocks
require 'timeout' status = Timeout::timeout(5) { # Something that should be interrupted if it takes more than 5 seconds... }
Timeout
provides a way to auto-terminate a potentially long-running operation if it hasn’t finished in a fixed amount of time.
Previous versions didn’t use a module for namespacing, however timeout
is provided for backwards compatibility. You should prefer Timeout.timeout
instead.
© 2000 Network Applied Communication Laboratory, Inc.
© 2000 Information-technology Promotion Agency, Japan
Raised when attempting to uninstall a gem that isn’t in GEM_HOME.
Mixin methods for –version and –platform Gem::Command
options.
A C union wrapper
Eigenvalues and eigenvectors of a real matrix.
Computes the eigenvalues and eigenvectors of a matrix A.
If A is diagonalizable, this provides matrices V and D such that A = V*D*V.inv, where D is the diagonal matrix with entries equal to the eigenvalues and V is formed by the eigenvectors.
If A is symmetric, then V is orthogonal and thus A = V*D*V.t
For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a m-by-m permutation matrix P so that L*U = P*A. If m < n, then L is m-by-m and U is m-by-n.
The LUP decomposition with pivoting always exists, even if the matrix is singular, so the constructor will never fail. The primary use of the LU decomposition is in the solution of square systems of simultaneous linear equations. This will fail if singular? returns true.