Results for: "match"

Iterates over the elements of range, passing each in turn to the block.

The each method can only be used if the begin object of the range supports the succ method. A TypeError is raised if the object does not have succ method defined (like Float).

If no block is given, an enumerator is returned instead.

(10..15).each {|n| print n, ' ' }
# prints: 10 11 12 13 14 15

(2.5..5).each {|n| print n, ' ' }
# raises: TypeError: can't iterate from Float

By using binary search, finds a value in range which meets the given condition in O(log n) where n is the size of the range.

You can use this method in two use cases: a find-minimum mode and a find-any mode. In either case, the elements of the range must be monotone (or sorted) with respect to the block.

In find-minimum mode (this is a good choice for typical use case), the block must return true or false, and there must be a value x so that:

If x is within the range, this method returns the value x. Otherwise, it returns nil.

ary = [0, 4, 7, 10, 12]
(0...ary.size).bsearch {|i| ary[i] >= 4 } #=> 1
(0...ary.size).bsearch {|i| ary[i] >= 6 } #=> 2
(0...ary.size).bsearch {|i| ary[i] >= 8 } #=> 3
(0...ary.size).bsearch {|i| ary[i] >= 100 } #=> nil

(0.0...Float::INFINITY).bsearch {|x| Math.log(x) >= 0 } #=> 1.0

In find-any mode (this behaves like libc’s bsearch(3)), the block must return a number, and there must be two values x and y (x <= y) so that:

This method returns any value which is within the intersection of the given range and x…y (if any). If there is no value that satisfies the condition, it returns nil.

ary = [0, 100, 100, 100, 200]
(0..4).bsearch {|i| 100 - ary[i] } #=> 1, 2 or 3
(0..4).bsearch {|i| 300 - ary[i] } #=> nil
(0..4).bsearch {|i|  50 - ary[i] } #=> nil

You must not mix the two modes at a time; the block must always return either true/false, or always return a number. It is undefined which value is actually picked up at each iteration.

Returns the maximum value in the range. Returns nil if the begin value of the range larger than the end value. Returns nil if the begin value of an exclusive range is equal to the end value.

Can be given an optional block to override the default comparison method a <=> b.

(10..20).max    #=> 20

Returns a two element array which contains the minimum and the maximum value in the range.

Can be given an optional block to override the default comparison method a <=> b.

Returns a new set that is a copy of the set, flattening each containing set recursively.

Equivalent to Set#flatten, but replaces the receiver with the result in place. Returns nil if no modifications were made.

Calls the given block once for each element in the set, passing the element as parameter. Returns an enumerator if no block is given.

No documentation available

Allocates space for a new object of class’s class and does not call initialize on the new instance. The returned object must be an instance of class.

klass = Class.new do
  def initialize(*args)
    @initialized = true
  end

  def initialized?
    @initialized || false
  end
end

klass.allocate.initialized? #=> false
No documentation available

Returns clean pathname of self with consecutive slashes and useless dots removed. The filesystem is not accessed.

If consider_symlink is true, then a more conservative algorithm is used to avoid breaking symbolic linkages. This may retain more .. entries than absolutely necessary, but without accessing the filesystem, this can’t be avoided.

See Pathname#realpath.

The opposite of Pathname#absolute?

It returns false if the pathname begins with a slash.

p = Pathname.new('/im/sure')
p.relative?
    #=> false

p = Pathname.new('not/so/sure')
p.relative?
    #=> true

Returns the children of the directory (files and subdirectories, not recursive) as an array of Pathname objects.

By default, the returned pathnames will have enough information to access the files. If you set with_directory to false, then the returned pathnames will contain the filename only.

For example:

pn = Pathname("/usr/lib/ruby/1.8")
pn.children
    # -> [ Pathname:/usr/lib/ruby/1.8/English.rb,
           Pathname:/usr/lib/ruby/1.8/Env.rb,
           Pathname:/usr/lib/ruby/1.8/abbrev.rb, ... ]
pn.children(false)
    # -> [ Pathname:English.rb, Pathname:Env.rb, Pathname:abbrev.rb, ... ]

Note that the results never contain the entries . and .. in the directory because they are not children.

Creates a full path, including any intermediate directories that don’t yet exist.

See FileUtils.mkpath and FileUtils.mkdir_p

Returns the real (absolute) pathname for self in the actual filesystem.

Does not contain symlinks or useless dots, .. and ..

All components of the pathname must exist when this method is called.

Returns the real (absolute) pathname of self in the actual filesystem.

Does not contain symlinks or useless dots, .. and ..

The last component of the real pathname can be nonexistent.

Returns the last access time for the file.

See File.atime.

Changes file permissions.

See File.chmod.

Same as Pathname.chmod, but does not follow symbolic links.

See File.lchmod.

Change owner and group of the file.

See File.chown.

Same as Pathname.chown, but does not follow symbolic links.

See File.lchown.

Returns a File::Stat object.

See File.stat.

See File.lstat.

Truncates the file to length bytes.

See File.truncate.

See FileTest.chardev?.

Search took: 3ms  ·  Total Results: 2234