Evaluates a string containing Ruby source code, or the given block, within the context of the receiver (obj). In order to set the context, the variable self
is set to obj while the code is executing, giving the code access to obj’s instance variables and private methods.
When instance_eval
is given a block, obj is also passed in as the block’s only argument.
When instance_eval
is given a String
, the optional second and third parameters supply a filename and starting line number that are used when reporting compilation errors.
class KlassWithSecret def initialize @secret = 99 end private def the_secret "Ssssh! The secret is #{@secret}." end end k = KlassWithSecret.new k.instance_eval { @secret } #=> 99 k.instance_eval { the_secret } #=> "Ssssh! The secret is 99." k.instance_eval {|obj| obj == self } #=> true
Allow connections from Socket
soc
?
Allow connections from addrinfo addr
? It must be formatted like Socket#peeraddr:
["AF_INET", 10, "lc630", "192.0.2.1"]
Waits until all specified threads have terminated. If a block is provided, it is executed for each thread as they terminate.
Waits until all of the specified threads are terminated. If a block is supplied for the method, it is executed for each thread termination.
Raises exceptions in the same manner as next_wait
.
Waits until all specified threads have terminated. If a block is provided, it is executed for each thread as they terminate.
Waits until all of the specified threads are terminated. If a block is supplied for the method, it is executed for each thread termination.
Raises exceptions in the same manner as next_wait
.
Return the called name of the method being called
Returns the current execution stack—an array containing backtrace location objects.
See Thread::Backtrace::Location
for more information.
The optional start parameter determines the number of initial stack entries to omit from the top of the stack.
A second optional length
parameter can be used to limit how many entries are returned from the stack.
Returns nil
if start is greater than the size of current execution stack.
Optionally you can pass a range, which will return an array containing the entries within the specified range.
Returns an array containing all elements of enum
for which the given block
returns a true value.
If no block is given, an Enumerator
is returned instead.
(1..10).find_all { |i| i % 3 == 0 } #=> [3, 6, 9] [1,2,3,4,5].select { |num| num.even? } #=> [2, 4] [:foo, :bar].filter { |x| x == :foo } #=> [:foo]
See also Enumerable#reject
.
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.
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.
Returns true
if the named file is writable by the real user and group id of this process. See access(3)
Returns true
if the named file is executable by the real user and group id of this process. See access(3).
Calls the constructed Function
, with args
. Caller must ensure the underlying function is called in a thread-safe manner if running in a multi-threaded process.
For an example see Fiddle::Function
Allocates a C struct with the types
provided.
When the instance is garbage collected, the C function func
is called.
Allocates a C union the types
provided.
When the instance is garbage collected, the C function func
is called.
Fiddle::Pointer.malloc(size, freefunc = nil) => fiddle pointer instance
Allocate size
bytes of memory and associate it with an optional freefunc
that will be called when the pointer is garbage collected.
freefunc
must be an address pointing to a function or an instance of Fiddle::Function
Logs a message
at the fatal (syslog err) log level, or logs the message returned from the block.
Returns all specifications. This method is discouraged from use. You probably want to use one of the Enumerable
methods instead.
Sets the known specs to specs
. Not guaranteed to work for you in the future. Use at your own risk. Caveat emptor. Doomy doom doom. Etc
etc.