Returns self
.
If called on a subclass of String, converts the receiver to a String object.
Returns a new string with the characters from str in reverse order.
"stressed".reverse #=> "desserts"
Reverses str in place.
Prepend—Prepend the given string to str.
a = "world" a.prepend("hello ") #=> "hello world" a #=> "hello world"
If integer is greater than the length of str, returns a new String
of length integer with str left justified and padded with padstr; otherwise, returns str.
"hello".ljust(4) #=> "hello" "hello".ljust(20) #=> "hello " "hello".ljust(20, '1234') #=> "hello123412341234123"
If integer is greater than the length of str, returns a new String
of length integer with str right justified and padded with padstr; otherwise, returns str.
"hello".rjust(4) #=> "hello" "hello".rjust(20) #=> " hello" "hello".rjust(20, '1234') #=> "123412341234123hello"
Returns a copy of str with leading and trailing whitespace removed.
Whitespace is defined as any of the following characters: null, horizontal tab, line feed, vertical tab, form feed, carriage return, space.
" hello ".strip #=> "hello" "\tgoodbye\r\n".strip #=> "goodbye" "\x00\t\n\v\f\r ".strip #=> ""
Returns a copy of str with leading whitespace removed. See also String#rstrip
and String#strip
.
Refer to strip
for the definition of whitespace.
" hello ".lstrip #=> "hello " "hello".lstrip #=> "hello"
Returns a copy of str with trailing whitespace removed. See also String#lstrip
and String#strip
.
Refer to strip
for the definition of whitespace.
" hello ".rstrip #=> " hello" "hello".rstrip #=> "hello"
Removes leading and trailing whitespace from str. Returns nil
if str was not altered.
Refer to strip
for the definition of whitespace.
Removes leading whitespace from str, returning nil
if no change was made. See also String#rstrip!
and String#strip!
.
Refer to strip
for the definition of whitespace.
" hello ".lstrip #=> "hello " "hello".lstrip! #=> nil
Removes trailing whitespace from str, returning nil
if no change was made. See also String#lstrip!
and String#strip!
.
Refer to strip
for the definition of whitespace.
" hello ".rstrip #=> " hello" "hello".rstrip! #=> nil
Convert flt
to a BigDecimal
and return it.
require 'bigdecimal' require 'bigdecimal/util' 0.5.to_d # => #<BigDecimal:1dc69e0,'0.5E0',9(18)>
Returns a string containing a representation of self. As well as a fixed or exponential form of the float
, the call may return NaN
, Infinity
, and -Infinity
.
Since float
is already a float, returns self
.
Returns the largest integer less than or equal to float
.
1.2.floor #=> 1 2.0.floor #=> 2 (-1.2).floor #=> -2 (-2.0).floor #=> -2
Returns the value as a rational.
NOTE: 0.3.to_r isn’t the same as ‘0.3’.to_r. The latter is equivalent to ‘3/10’.to_r, but the former isn’t so.
2.0.to_r #=> (2/1) 2.5.to_r #=> (5/2) -0.75.to_r #=> (-3/4) 0.0.to_r #=> (0/1)
See rationalize.
Resumes the fiber from the point at which the last Fiber.yield
was called, or starts running it if it is the first call to resume
. Arguments passed to resume will be the value of the Fiber.yield
expression or will be passed as block parameters to the fiber’s block if this is the first resume
.
Alternatively, when resume is called it evaluates to the arguments passed to the next Fiber.yield
statement inside the fiber’s block or to the block value if it runs to completion without any Fiber.yield
Returns the current fiber. You need to require 'fiber'
before using this method. If you are not running in the context of a fiber this method will return the root fiber.
Reads the next entry from dir and returns it as a string. Returns nil
at the end of the stream.
d = Dir.new("testdir") d.read #=> "." d.read #=> ".." d.read #=> "config.h"
Repositions dir to the first entry.
d = Dir.new("testdir") d.read #=> "." d.rewind #=> #<Dir:0x401b3fb0> d.read #=> "."
Returns true
if the named file is a directory, false
otherwise.
Deprecated method. Don’t use.