Returns a new array with the concatenated results of running block once for every element in enum.
If no block is given, an enumerator is returned instead.
[1, 2, 3, 4].flat_map { |e| [e, -e] } #=> [1, -1, 2, -2, 3, -3, 4, -4] [[1, 2], [3, 4]].flat_map { |e| e + [100] } #=> [1, 2, 100, 3, 4, 100]
Returns a new array with the concatenated results of running block once for every element in enum.
If no block is given, an enumerator is returned instead.
[1, 2, 3, 4].flat_map { |e| [e, -e] } #=> [1, -1, 2, -2, 3, -3, 4, -4] [[1, 2], [3, 4]].flat_map { |e| e + [100] } #=> [1, 2, 100, 3, 4, 100]
Generate a JSON
document from the Ruby data structure obj and return it. This method disables the checks for circles in Ruby objects.
WARNING: Be careful not to pass any Ruby data structures with circles as obj argument because this will cause JSON
to go into an infinite loop.
Generate a JSON
document from the Ruby data structure obj and return it. The returned document is a prettier form of the document returned by unparse.
The opts argument can be used to configure the generator. See the generate method for a more detailed explanation.
Returns the source file origin from the given object
.
See ::trace_object_allocations
for more information and examples.
Returns the original line from source for from the given object
.
See ::trace_object_allocations
for more information and examples.
Return consuming memory size of obj.
Note that the return size is incomplete. You need to deal with this information as only a HINT. Especially, the size of T_DATA
may not be correct.
This method is only expected to work with C Ruby.
From Ruby 2.2, memsize_of
(obj) returns a memory size includes sizeof(RVALUE).
Adds aProc as a finalizer, to be called after obj was destroyed. The object ID of the obj will be passed as an argument to aProc. If aProc is a lambda or method, make sure it can be called with a single argument.
Removes all finalizers for obj.
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 multiple documents given in yaml
. Returns the parsed documents as a list. If a block is given, each document will be converted to Ruby and passed to the block during parsing
Example:
Psych.load_stream("--- foo\n...\n--- bar\n...") # => ['foo', 'bar'] list = [] Psych.load_stream("--- foo\n...\n--- bar\n...") do |ruby| list << ruby end list # => ['foo', 'bar']
Returns the version of libyaml being used
Returns the number of malloc() allocations.
Only available if ruby was built with CALC_EXACT_MALLOC_SIZE
.
Try to activate a gem containing path
. Returns true if activation succeeded or wasn’t needed because it was already activated. Returns false if it can’t find the path in a gem.
The mode needed to read a file as straight binary.
Finds the user’s home directory.
Loads YAML, preferring Psych
Safely read a file in binary mode on all platforms.
Safely write a file in binary mode on all platforms.
The home directory for the user.
Is this a windows platform?
Default options for gem commands for Ruby implementers.
The options here should be structured as an array of string “gem” command names as keys and a string of the default options as values.
Example:
def self.platform_defaults
{ 'install' => '--no-rdoc --no-ri --env-shebang', 'update' => '--no-rdoc --no-ri --env-shebang' }
end
Allows toggling Windows behavior. This method is available when requiring ‘rubygems/test_case’