With a block given returns a hash:
Each key is a return value from the block.
Each value is an array of those elements for which the block returned that key.
Examples:
g = (1..6).group_by {|i| i%3 } g # => {1=>[1, 4], 2=>[2, 5], 0=>[3, 6]} h = {foo: 0, bar: 1, baz: 0, bat: 1} g = h.group_by {|key, value| value } g # => {0=>[[:foo, 0], [:baz, 0]], 1=>[[:bar, 1], [:bat, 1]]}
With no block given, returns an Enumerator
.
Calls the block with successive elements as long as the block returns a truthy value; returns an array of all elements after that point:
(1..4).drop_while{|i| i < 3 } # => [3, 4] h = {foo: 0, bar: 1, baz: 2} a = h.drop_while{|element| key, value = *element; value < 2 } a # => [[:baz, 2]]
With no block given, returns an Enumerator
.
Arguments obj
and opts
here are the same as arguments obj
and opts
in JSON.generate
.
Default options are:
{ indent: ' ', # Two spaces space: ' ', # One space array_nl: "\n", # Newline object_nl: "\n" # Newline }
Example:
obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}} json = JSON.pretty_generate(obj) puts json
Output:
{ "foo": [ "bar", "baz" ], "bat": { "bam": 0, "bad": 1 } }
Returns true if this monitor is locked by any thread
Enters exclusive section and executes the block. Leaves the exclusive section automatically when the block exits. See example under MonitorMixin
.
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.
Returns garbage collector generation for the given object
.
class B include ObjectSpace def foo trace_object_allocations do obj = Object.new p "Generation is #{allocation_generation(obj)}" end end end B.new.foo #=> "Generation is 3"
See ::trace_object_allocations
for more information and examples.
Adds a pre-install hook that will be passed an Gem::Installer
instance when Gem::Installer#install
is called. If the hook returns false
then the install will be aborted.
Adds a hook that will get run before Gem::Specification.reset
is run.
Adds a pre-uninstall hook that will be passed an Gem::Uninstaller
instance and the spec that will be uninstalled when Gem::Uninstaller#uninstall
is called
Adds DidYouMean
functionality to an error using a given spell checker
Accepts a Thread::Backtrace::Location
object and returns a Prism::Node
corresponding to the backtrace location in the source code.
Returns whether or not macro
is defined either in the common header files or within any headers
you provide.
Any options you pass to opt
are passed along to the compiler.
SyntaxSuggest.handle_error
[Public]
Takes a ‘SyntaxError` exception, uses the error message to locate the file. Then the file will be analyzed to find the location of the syntax error and emit that location to stderr.
Example:
begin require 'bad_file' rescue => e SyntaxSuggest.handle_error(e) end
By default it will re-raise the exception unless ‘re_raise: false`. The message output location can be configured using the `io: $stderr` input.
If a valid filename cannot be determined, the original exception will be re-raised (even with ‘re_raise: false`).
Returns tokens corresponding to the location of the node. Returns nil
if keep_tokens
is not enabled when parse method is called.
root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2", keep_tokens: true) root.tokens # => [[0, :tIDENTIFIER, "x", [1, 0, 1, 1]], [1, :tSP, " ", [1, 1, 1, 2]], ...] root.tokens.map{_1[2]}.join # => "x = 1 + 2"
Token is an array of:
id
token type
source code text
location [ first_lineno
, first_column
, last_lineno
, last_column
]
Sends “close notify” to the peer and tries to shut down the SSL
connection gracefully.
If a timestamp token is present, this returns it in the form of a OpenSSL::PKCS7
.
Restore session state from the session’s FileStore
file.
Returns the session state as a hash.
Restore (empty) session state.
Restore session state from the session’s PStore
file.
Returns the session state as a hash.