Check if gem name
version version
is installed.
Returns true
if all elements of self
meet a given criterion.
With no block given and no argument, returns true
if self
contains only truthy elements, false
otherwise:
[0, 1, :foo].all? # => true [0, nil, 2].all? # => false [].all? # => true
With a block given and no argument, calls the block with each element in self
; returns true
if the block returns only truthy values, false
otherwise:
[0, 1, 2].all? { |element| element < 3 } # => true [0, 1, 2].all? { |element| element < 2 } # => false
If argument obj
is given, returns true
if obj.===
every element, false
otherwise:
['food', 'fool', 'foot'].all?(/foo/) # => true ['food', 'drink'].all?(/bar/) # => false [].all?(/foo/) # => true [0, 0, 0].all?(0) # => true [0, 1, 2].all?(1) # => false
Related: Enumerable#all?
Returns true
if all bits that are set (=1) in mask
are also set in self
; returns false
otherwise.
Example values:
0b1010101 self 0b1010100 mask 0b1010100 self & mask true self.allbits?(mask) 0b1010100 self 0b1010101 mask 0b1010100 self & mask false self.allbits?(mask)
Related: Integer#anybits?
, Integer#nobits?
.
Returns a string containing the characters in self
; the first character is upcased; the remaining characters are downcased:
s = 'hello World!' # => "hello World!" s.capitalize # => "Hello world!"
The casing may be affected by the given options
; see Case Mapping.
Related: String#capitalize!
.
Upcases the first character in self
; downcases the remaining characters; returns self
if any changes were made, nil
otherwise:
s = 'hello World!' # => "hello World!" s.capitalize! # => "Hello world!" s # => "Hello world!" s.capitalize! # => nil
The casing may be affected by the given options
; see Case Mapping.
Related: String#capitalize
.
Invokes the continuation. The program continues from the end of the callcc
block. If no arguments are given, the original callcc
returns nil
. If one argument is given, callcc
returns it. Otherwise, an array containing args is returned.
callcc {|cont| cont.call } #=> nil callcc {|cont| cont.call 1 } #=> 1 callcc {|cont| cont.call 1, 2, 3 } #=> [1, 2, 3]
Allocates space for a new object of class’s class and does not call initialize on the new instance. The returned object must be an instance of class.
klass = Class.new do def initialize(*args) @initialized = true end def initialized? @initialized || false end end klass.allocate.initialized? #=> false
Returns true
if the log level allows entries with severity Logger::FATAL to be written, false
otherwise. See Log Level.
Sets the log level to Logger::FATAL. See Log Level.
Equivalent to calling add
with severity Logger::FATAL
.
Invokes the block, setting the block’s parameters to the values in params using something close to method calling semantics. Returns the value of the last expression evaluated in the block.
a_proc = Proc.new {|scalar, *values| values.map {|value| value*scalar } } a_proc.call(9, 1, 2, 3) #=> [9, 18, 27] a_proc[9, 1, 2, 3] #=> [9, 18, 27] a_proc.(9, 1, 2, 3) #=> [9, 18, 27] a_proc.yield(9, 1, 2, 3) #=> [9, 18, 27]
Note that prc.()
invokes prc.call()
with the parameters given. It’s syntactic sugar to hide “call”.
For procs created using lambda
or ->()
an error is generated if the wrong number of parameters are passed to the proc. For procs created using Proc.new
or Kernel.proc
, extra parameters are silently discarded and missing parameters are set to nil
.
a_proc = proc {|a,b| [a,b] } a_proc.call(1) #=> [1, nil] a_proc = lambda {|a,b| [a,b] } a_proc.call(1) # ArgumentError: wrong number of arguments (given 1, expected 2)
See also Proc#lambda?
.
Invokes the meth with the specified arguments, returning the method’s return value.
m = 12.method("+") m.call(3) #=> 15 m.call(20) #=> 32
Generates a Continuation
object, which it passes to the associated block. You need to require 'continuation'
before using this method. Performing a cont.call
will cause the callcc
to return (as will falling through the end of the block). The value returned by the callcc
is the value of the block, or the value passed to cont.call
. See class Continuation
for more details. Also see Kernel#throw
for an alternative mechanism for unwinding a call stack.
Returns the called name of the current method as a Symbol
. If called outside of a method, it returns nil
.
Invokes Posix system call syscall(2), which calls a specified function.
Calls the operating system function identified by integer_callno
; returns the result of the function or raises SystemCallError
if it failed. The effect of the call is platform-dependent. The arguments and returned value are platform-dependent.
For each of arguments
: if it is an integer, it is passed directly; if it is a string, it is interpreted as a binary sequence of bytes. There may be as many as nine such arguments.
Arguments integer_callno
and argument
, as well as the returned value, are platform-dependent.
Note: Method
syscall
is essentially unsafe and unportable. The DL (Fiddle
) library is preferred for safer and a bit more portable programming.
Not implemented on all platforms.
Returns the current execution stack—an array containing strings in the form file:line
or file:line: in `method'
.
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.
def a(skip) caller(skip) end def b(skip) a(skip) end def c(skip) b(skip) end c(0) #=> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10:in `<main>'"] c(1) #=> ["prog:5:in `b'", "prog:8:in `c'", "prog:11:in `<main>'"] c(2) #=> ["prog:8:in `c'", "prog:12:in `<main>'"] c(3) #=> ["prog:13:in `<main>'"] c(4) #=> [] c(5) #=> nil
Returns whether every element meets a given criterion.
With no argument and no block, returns whether every element is truthy:
(1..4).all? # => true %w[a b c d].all? # => true [1, 2, nil].all? # => false ['a','b', false].all? # => false [].all? # => true
With argument pattern
and no block, returns whether for each element element
, pattern === element
:
(1..4).all?(Integer) # => true (1..4).all?(Numeric) # => true (1..4).all?(Float) # => false %w[bar baz bat bam].all?(/ba/) # => true %w[bar baz bat bam].all?(/bar/) # => false %w[bar baz bat bam].all?('ba') # => false {foo: 0, bar: 1, baz: 2}.all?(Array) # => true {foo: 0, bar: 1, baz: 2}.all?(Hash) # => false [].all?(Integer) # => true
With a block given, returns whether the block returns a truthy value for every element:
(1..4).all? {|element| element < 5 } # => true (1..4).all? {|element| element < 4 } # => false {foo: 0, bar: 1, baz: 2}.all? {|key, value| value < 3 } # => true {foo: 0, bar: 1, baz: 2}.all? {|key, value| value < 2 } # => false
Allocate size
bytes of memory and return the integer memory address for the allocated memory.
Change the size of the memory allocated at the memory location addr
to size
bytes. Returns the memory address of the reallocated memory, which may be different than the address passed in.
Set
the default id conversion object.
This is expected to be an instance such as DRb::DRbIdConv
that responds to to_id
and to_obj
that can convert objects to and from DRb
references.
See DRbServer#default_id_conv.
Set
the default id conversion object.
This is expected to be an instance such as DRb::DRbIdConv
that responds to to_id
and to_obj
that can convert objects to and from DRb
references.
See DRbServer#default_id_conv.