Collects (as in Enumerable#collect
) over the elements of this vector and v
in conjunction.
Like Array#collect
.
Returns a new vector with the same direction but with norm 1.
v = Vector[5,8,2].normalize # => Vector[0.5184758473652127, 0.8295613557843402, 0.20739033894608505] v.norm => 1.0
Looks up the first IP address for name
.
Looks up all IP address for name
.
Looks up the first IP address for name
.
Looks up all IP address for name
.
Basically the same as ::new
. However, if class Thread
is subclassed, then calling start
in that subclass will not invoke the subclass’s initialize
method.
Causes the given thread
to exit, see also Thread::exit
.
count = 0 a = Thread.new { loop { count += 1 } } sleep(0.1) #=> 0 Thread.kill(a) #=> #<Thread:0x401b3d30 dead> count #=> 93947 a.alive? #=> false
Waits for thr
to complete, using join
, and returns its value or raises the exception which terminated the thread.
a = Thread.new { 2 + 2 } a.value #=> 4 b = Thread.new { raise 'something went wrong' } b.value #=> RuntimeError: something went wrong
Terminates thr
and schedules another thread to be run, returning the terminated Thread
. If this is the main thread, or the last thread, exits the process.
Returns the status of thr
.
"sleep"
Returned if this thread is sleeping or waiting on I/O
"run"
When this thread is executing
"aborting"
If this thread is aborting
false
When this thread is terminated normally
nil
If terminated with an exception.
a = Thread.new { raise("die now") } b = Thread.new { Thread.stop } c = Thread.new { Thread.exit } d = Thread.new { sleep } d.kill #=> #<Thread:0x401b3678 aborting> a.status #=> nil b.status #=> "sleep" c.status #=> false d.status #=> "aborting" Thread.current.status #=> "run"
Returns true
if thr
is running or sleeping.
thr = Thread.new { } thr.join #=> #<Thread:0x401b3fb0 dead> Thread.current.alive? #=> true thr.alive? #=> false
Wakes up the first thread in line waiting for this lock.
Returns internal information of TracePoint
.
The contents of the returned value are implementation specific. It may be changed in future.
This method is only for debugging TracePoint
itself.
Return the tag object which was called for.
Return the return value which was called for.
Create a new BigDecimal
object.
The initial value, as an Integer
, a Float
, a Rational
, a BigDecimal
, or a String
.
If it is a String
, spaces are ignored and unrecognized characters terminate the value.
The number of significant digits, as an Integer
. If omitted or 0, the number of significant digits is determined from the initial value.
The actual number of significant digits used in computation is usually larger than the specified number.
Whether an exception should be raised on invalid arguments. true
by default, if passed false
, just returns nil
for invalid.
TypeError
If the initial
type is neither Integer
, Float
, Rational
, nor BigDecimal
, this exception is raised.
TypeError
If the digits
is not an Integer
, this exception is raised.
ArgumentError
If initial
is a Float
, and the digits
is larger than Float::DIG + 1, this exception is raised.
ArgumentError
If the initial
is a Float
or Rational
, and the digits
value is omitted, this exception is raised.
Returns x/y
or arg
as a Rational
.
Rational(2, 3) #=> (2/3) Rational(5) #=> (5/1) Rational(0.5) #=> (1/2) Rational(0.3) #=> (5404319552844595/18014398509481984) Rational("2/3") #=> (2/3) Rational("0.3") #=> (3/10) Rational("10 cents") #=> ArgumentError Rational(nil) #=> TypeError Rational(1, nil) #=> TypeError Rational("10 cents", exception: false) #=> nil
Syntax of the string form:
string form = extra spaces , rational , extra spaces ; rational = [ sign ] , unsigned rational ; unsigned rational = numerator | numerator , "/" , denominator ; numerator = integer part | fractional part | integer part , fractional part ; denominator = digits ; integer part = digits ; fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ; sign = "-" | "+" ; digits = digit , { digit | "_" , digit } ; digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; extra spaces = ? \s* ? ;
See also String#to_r
.
Evaluates the Ruby expression(s) in string. If binding is given, which must be a Binding
object, the evaluation is performed in its context. If the optional filename and lineno parameters are present, they will be used when reporting syntax errors.
def get_binding(str) return binding end str = "hello" eval "str + ' Fred'" #=> "hello Fred" eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
Returns a new array with the results of running block once for every element in enum.
If no block is given, an enumerator is returned instead.
(1..4).map { |i| i*i } #=> [1, 4, 9, 16] (1..4).collect { "cat" } #=> ["cat", "cat", "cat", "cat"]
Returns first n elements from enum.
a = [1, 2, 3, 4, 5, 0] a.take(3) #=> [1, 2, 3] a.take(30) #=> [1, 2, 3, 4, 5, 0]
Computes the arctangent of decimal
to the specified number of digits of precision, numeric
.
If decimal
is NaN, returns NaN.
BigMath.atan(BigDecimal('-1'), 16).to_s #=> "-0.785398163397448309615660845819878471907514682065e0"
Determines the equality of two numbers by comparing to zero, or using the epsilon value