Divides the set into a set of subsets according to the commonality defined by the given block.
If the arity of the block is 2, elements o1 and o2 are in common if block.call(o1, o2) is true. Otherwise, elements o1 and o2 are in common if block.call(o1) == block.call(o2).
require 'set' numbers = Set[1, 3, 4, 6, 9, 10, 11] set = numbers.divide { |i,j| (i - j).abs == 1 } set #=> #<Set: {#<Set: {1}>, # #<Set: {11, 9, 10}>, # #<Set: {3, 4}>, # #<Set: {6}>}>
Returns an enumerator if no block is given.
Returns the binding associated with prc. Note that Kernel#eval
accepts either a Proc
or a Binding
object as its second parameter.
def fred(param) proc {} end b = fred(99) eval("param", b.binding) #=> 99
Deactivates the trace
Return true if trace was enabled. Return false if trace was disabled.
trace.enabled? #=> true trace.disable #=> true (previous status) trace.enabled? #=> false trace.disable #=> false
If a block is given, the trace will only be disable within the scope of the block.
trace.enabled? #=> true trace.disable do trace.enabled? # only disabled for this block end trace.enabled? #=> true
Note: You cannot access event hooks within the block.
trace.disable { p tp.lineno } #=> RuntimeError: access from outside
Return the generated binding object from event
When RubyGems is required, Kernel#require
is replaced with our own which is capable of loading gems on demand.
When you call require 'x'
, this is what happens:
If the file can be loaded from the existing Ruby loadpath, it is.
Otherwise, installed gems are searched for a file that matches. If it’s found in gem ‘y’, that gem is activated (added to the loadpath).
The normal require
functionality of returning false if that file has already been loaded is preserved.
Returns a Binding
object, describing the variable and method bindings at the point of call. This object can be used when calling eval
to execute the evaluated command in this environment. See also the description of class Binding
.
def get_binding(param) binding end b = get_binding("hello") eval("param", b) #=> "hello"
Returns the first element, or the first n
elements, of the enumerable. If the enumerable is empty, the first form returns nil
, and the second form returns an empty array.
%w[foo bar baz].first #=> "foo" %w[foo bar baz].first(2) #=> ["foo", "bar"] %w[foo bar baz].first(10) #=> ["foo", "bar", "baz"] [].first #=> nil [].first(10) #=> []
Returns a Digest
subclass by name
require 'openssl' OpenSSL::Digest("MD5") # => OpenSSL::Digest::MD5 Digest("Foo") # => NameError: wrong constant name Foo
Returns a Digest
subclass by name
require 'openssl' OpenSSL::Digest("MD5") # => OpenSSL::Digest::MD5 Digest("Foo") # => NameError: wrong constant name Foo
Change what’s displayed on the screen to reflect the current contents.
See GNU Readline’s rl_redisplay function.
Raises NotImplementedError
if the using readline library does not support.
Disables garbage collection, returning true
if garbage collection was already disabled.
GC.disable #=> false GC.disable #=> true
Redirects to a path ending in /
Returns true
if the entry is a directory (i.e., the value of the type fact is dir, cdir, or pdir).
Creates a new directory in the tar file name
with mode
Returns a string usable in Dir.glob
to match all requirable paths for this spec.
Make directories for index generation
The path where installed executables live
Iterates over keys and objects in a weakly referenced object
Calls the given block once for each key
, value
pair in the database.
Returns self
.
Returns true
if the MKD command may be used to create a new directory within the directory.
Returns the hash value of a given string. This is equivalent to Digest::Class.new(*parameters)
.digest(string), where extra parameters, if any, are passed through to the constructor and the string is passed to digest()
.
Returns the hex-encoded hash value of a given string. This is almost equivalent to Digest.hexencode
(Digest::Class.new(*parameters)
.digest(string)).