Iterates the given block, passing in integer values from int
up to and including limit
.
If no block is given, an Enumerator
is returned instead.
For example:
5.upto(10) { |i| print i, " " } #=> 5 6 7 8 9 10
Iterates the given block, passing decreasing values from int
down to and including limit
.
If no block is given, an Enumerator
is returned instead.
5.downto(1) { |n| print n, ".. " } print " Liftoff!\n" #=> "5.. 4.. 3.. 2.. 1.. Liftoff!"
Returns the int
itself.
?a.ord #=> 97
This method is intended for compatibility to character constant in Ruby 1.9.
For example, ?a.ord returns 97 both in 1.8 and 1.9.
Converts int
to a Float
. If int
doesn’t fit in a Float
, the result is infinity.
Returns the largest number less than or equal to int
in decimal digits (default 0 digits).
Precision may be negative. Returns a floating point number when ndigits
is positive, self
for zero, and floor down for negative.
1.floor #=> 1 1.floor(2) #=> 1.0 15.floor(-1) #=> 10
Returns the remainder after dividing big by numeric as:
x.remainder(y) means x-y*(x/y).truncate
Examples
5.remainder(3) #=> 2 -5.remainder(3) #=> -2 5.remainder(-3) #=> 2 -5.remainder(-3) #=> -2 -1234567890987654321.remainder(13731) #=> -6966 -1234567890987654321.remainder(13731.24) #=> -9906.22531493148
See Numeric#divmod
.
Returns the value as a rational.
1.to_r #=> (1/1) (1<<64).to_r #=> (18446744073709551616/1)
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
.
The content of the TempIO
as a String.
Replaces the contents of the set with the contents of the given enumerable object and returns self.
Converts the set to an array. The order of elements is uncertain.
Equivalent to Set#delete_if
, but returns nil if no changes were made. Returns an enumerator if no block is given.
Creates a temporary file as usual File
object (not Tempfile
). It doesn’t use finalizer and delegation.
If no block is given, this is similar to Tempfile.new
except creating File
instead of Tempfile
. The created file is not removed automatically. You should use File.unlink
to remove it.
If a block is given, then a File
object will be constructed, and the block is invoked with the object as the argument. The File
object will be automatically closed and the temporary file is removed after the block terminates. The call returns the value of the block.
In any case, all arguments (+*args+) will be treated as Tempfile.new
.
Tempfile.create('foo', '/home/temp') do |f| ... do something with f ... end
The string representation of true
is “true”.
‘nuf said…
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.
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.
Returns an array of Thread
objects for all threads that are either runnable or stopped.
Thread.new { sleep(200) } Thread.new { 1000000.times {|i| i*i } } Thread.new { Thread.stop } Thread.list.each {|t| p t}
This will produce:
#<Thread:0x401b3e84 sleep> #<Thread:0x401b3f38 run> #<Thread:0x401b3fb0 sleep> #<Thread:0x401bdf4c run>