Returns the binding associated with prc.
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.
Note that for c_call
and c_return
events, the binding returned is the binding of the nearest Ruby method calling the C method, since C methods themselves do not have bindings.
Loads the given name
, returning true
if successful and false
if the feature is already loaded.
If the filename neither resolves to an absolute path nor starts with ‘./’ or ‘../’, the file will be searched for in the library directories listed in $LOAD_PATH
($:
). If the filename starts with ‘./’ or ‘../’, resolution is based on Dir.pwd
.
If the filename has the extension “.rb”, it is loaded as a source file; if the extension is “.so”, “.o”, or “.dll”, or the default shared library extension on the current platform, Ruby loads the shared library as a Ruby extension. Otherwise, Ruby tries adding “.rb”, “.so”, and so on to the name until found. If the file named cannot be found, a LoadError
will be raised.
For Ruby extensions the filename given may use any shared library extension. For example, on Linux the socket extension is “socket.so” and require 'socket.dll'
will load the socket extension.
The absolute path of the loaded file is added to $LOADED_FEATURES
($"
). A file will not be loaded again if its path already appears in $"
. For example, require 'a'; require './a'
will not load a.rb
again.
require "my-library.rb" require "db-driver"
Any constants or globals within the loaded source file will be available in the calling program’s global namespace. However, local variables will not be propagated to the loading environment.
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 elements.
With no argument, returns the first element, or nil
if there is none:
(1..4).first # => 1 %w[a b c].first # => "a" {foo: 1, bar: 1, baz: 2}.first # => [:foo, 1] [].first # => nil
With integer argument n
, returns an array containing the first n
elements that exist:
(1..4).first(2) # => [1, 2] %w[a b c d].first(3) # => ["a", "b", "c"] %w[a b c d].first(50) # => ["a", "b", "c", "d"] {foo: 1, bar: 1, baz: 2}.first(2) # => [[:foo, 1], [:bar, 1]] [].first(2) # => []
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
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
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
.
@api private
Copied from ExtConfBuilder
Calls the given block with each successive character from self
; returns self
:
'hello'.each_char {|char| print char, ' ' } print "\n" 'тест'.each_char {|char| print char, ' ' } print "\n" 'こんにちは'.each_char {|char| print char, ' ' } print "\n"
Output:
h e l l o т е с т こ ん に ち は
Returns an enumerator if no block is given.
Changes the encoding of self
to encoding
, which may be a string encoding name or an Encoding
object; returns self:
s = 'łał' s.bytes # => [197, 130, 97, 197, 130] s.encoding # => #<Encoding:UTF-8> s.force_encoding('ascii') # => "\xC5\x82a\xC5\x82" s.encoding # => #<Encoding:US-ASCII>
Does not change the underlying bytes:
s.bytes # => [197, 130, 97, 197, 130]
Makes the change even if the given encoding
is invalid for self
(as is the change above):
s.valid_encoding? # => false s.force_encoding(Encoding::UTF_8) # => "łał" s.valid_encoding? # => true
Returns true
if self
is encoded correctly, false
otherwise:
"\xc2\xa1".force_encoding("UTF-8").valid_encoding? # => true "\xc2".force_encoding("UTF-8").valid_encoding? # => false "\x80".force_encoding("UTF-8").valid_encoding? # => false
Returns the number of decimal significant digits in self
.
BigDecimal("0").n_significant_digits # => 0 BigDecimal("1").n_significant_digits # => 1 BigDecimal("1.1").n_significant_digits # => 2 BigDecimal("3.1415").n_significant_digits # => 5 BigDecimal("-1e20").n_significant_digits # => 1 BigDecimal("1e-20").n_significant_digits # => 1 BigDecimal("Infinity").n_significant_digits # => 0 BigDecimal("-Infinity").n_significant_digits # => 0 BigDecimal("NaN").n_significant_digits # => 0
Converts a BigDecimal
to a String
of the form “nnnnnn.mmm”. This method is deprecated; use BigDecimal#to_s
(“F”) instead.
require 'bigdecimal/util' d = BigDecimal("3.14") d.to_digits # => "3.14"