Returns an array of the names of the thread-local variables (as Symbols).
thr = Thread.new do Thread.current.thread_variable_set(:cat, 'meow') Thread.current.thread_variable_set("dog", 'woof') end thr.join #=> #<Thread:0x401b3f10 dead> thr.thread_variables #=> [:dog, :cat]
Note that these are not fiber local variables. Please see Thread#[]
and Thread#thread_variable_get
for more details.
Returns true
if the given string (or symbol) exists as a thread-local variable.
me = Thread.current me.thread_variable_set(:oliver, "a") me.thread_variable?(:oliver) #=> true me.thread_variable?(:stanley) #=> false
Note that these are not fiber local variables. Please see Thread#[]
and Thread#thread_variable_get
for more details.
Returns the safe level.
This method is obsolete because $SAFE is a process global state. Simply check $SAFE.
Returns an array of the names of global variables.
global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
Returns the names of the current local variables.
fred = 1 for i in 1..10 # ... end local_variables #=> [:fred, :i]
Passes elements to the block until the block returns nil
or false
, then stops iterating and returns an array of all prior elements.
If no block is given, an enumerator is returned instead.
a = [1, 2, 3, 4, 5, 0] a.take_while { |i| i < 3 } #=> [1, 2]
Drops elements up to, but not including, the first element for which the block returns nil
or false
and returns an array containing the remaining elements.
If no block is given, an enumerator is returned instead.
a = [1, 2, 3, 4, 5, 0] a.drop_while { |i| i < 3 } #=> [3, 4, 5, 0]
Returns a hash that contains filename as key and coverage array as value. This is the same as ‘Coverage.result(stop: false, clear: false)`.
{ "file.rb" => [1, 2, nil], ... }
Dump the contents of the ruby heap as JSON
.
This method is only expected to work with C Ruby. This is an experimental method and is subject to change. In particular, the function signature and output format are not guaranteed to be compatible in future versions of ruby.
Parse a file at filename
. Returns the Psych::Nodes::Document
.
Raises a Psych::SyntaxError
when a YAML syntax error is detected.
Dump a list of objects as separate documents to a document stream.
Example:
Psych.dump_stream("foo\n ", {}) # => "--- ! \"foo\\n \"\n--- {}\n"
Load the document contained in filename
. Returns the yaml contained in filename
as a Ruby object, or if the file is empty, it returns the specified fallback
return value, which defaults to false
.
Delete text between start and end in the current line.
See GNU Readline’s rl_delete_text function.
Raises NotImplementedError
if the using readline library does not support.
Combine two Adler-32 check values in to one. alder1
is the first Adler-32 value, adler2
is the second Adler-32 value. len2
is the length of the string used to generate adler2
.
Returns the table for calculating CRC checksum as an array.
Returns true
if the named file is readable by the real user and group id of this process. See access(3).
If file_name is readable by others, returns an integer representing the file permission bits of file_name. Returns nil
otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2)
.
file_name can be an IO
object.
File.world_readable?("/etc/passwd") #=> 420 m = File.world_readable?("/etc/passwd") sprintf("%o", m) #=> "644"
Returns true
if the named file is writable by the real user and group id of this process. See access(3)
If file_name is writable by others, returns an integer representing the file permission bits of file_name. Returns nil
otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2)
.
file_name can be an IO
object.
File.world_writable?("/tmp") #=> 511 m = File.world_writable?("/tmp") sprintf("%o", m) #=> "777"
Returns true
if the named file is executable by the real user and group id of this process. See access(3).
Returns the Base64-decoded version of str
. This method complies with “Base 64 Encoding
with URL and Filename Safe Alphabet” in RFC 4648. The alphabet uses ‘-’ instead of ‘+’ and ‘_’ instead of ‘/’.
The padding character is optional. This method accepts both correctly-padded and unpadded input. Note that it still rejects incorrectly-padded input.
Reset the dir
and path
values. The next time dir
or path
is requested, the values will be calculated from scratch. This is mainly used by the unit tests to provide test isolation.
Returns a list of paths matching glob
that can be used by a gem to pick up features from other gems. For example:
Gem.find_files('rdoc/discover').each do |path| load path end
if check_load_path
is true (the default), then find_files
also searches $LOAD_PATH for files as well as gems.
Note that find_files
will return all files even if they are from different versions of the same gem. See also find_latest_files
An Array
of the default sources that come with RubyGems
Default home directory path to be used if an alternate value is not specified in the environment