Returns true
if self
is greater than 0, false
otherwise.
Returns true
if self
is less than 0, false
otherwise.
Returns self
.
Extracts data from self
, forming objects that become the elements of a new array; returns that array. See Packed Data.
Like String#unpack
, but unpacks and returns only the first extracted object. See Packed Data.
Returns a printable version of self
, enclosed in double-quotes, and with special characters escaped:
s = "foo\tbar\tbaz\n" s.inspect # => "\"foo\\tbar\\tbaz\\n\""
Returns a string containing the downcased characters in self
:
s = 'Hello World!' # => "Hello World!" s.downcase # => "hello world!"
The casing may be affected by the given options
; see Case Mapping.
Related: String#downcase!
, String#upcase
, String#upcase!
.
Downcases the characters in self
; returns self
if any changes were made, nil
otherwise:
s = 'Hello World!' # => "Hello World!" s.downcase! # => "hello world!" s # => "hello world!" s.downcase! # => nil
The casing may be affected by the given options
; see Case Mapping.
Related: String#downcase
, String#upcase
, String#upcase!
.
Interprets the leading substring of self
as a string of octal digits (with an optional sign) and returns the corresponding number; returns zero if there is no such leading substring:
'123'.oct # => 83 '-377'.oct # => -255 '0377non-numeric'.oct # => 255 'non-numeric'.oct # => 0
If self
starts with 0
, radix indicators are honored; see Kernel#Integer
.
Related: String#hex
.
Returns true
if self
contains other_string
, false
otherwise:
s = 'foo' s.include?('f') # => true s.include?('fo') # => true s.include?('food') # => false
Returns the total number of characters in self
that are specified by the given selectors
(see Multiple Character Selectors):
a = "hello world" a.count "lo" #=> 5 a.count "lo", "o" #=> 2 a.count "hello", "^l" #=> 4 a.count "ej-m" #=> 4 "hello^world".count "\\^aeiou" #=> 4 "hello-world".count "a\\-eo" #=> 4 c = "hello world\\r\\n" c.count "\\" #=> 2 c.count "\\A" #=> 0 c.count "X-\\w" #=> 3
Returns self
rounded to the nearest value with a precision of ndigits
decimal digits.
When ndigits
is non-negative, returns a float with ndigits
after the decimal point (as available):
f = 12345.6789 f.round(1) # => 12345.7 f.round(3) # => 12345.679 f = -12345.6789 f.round(1) # => -12345.7 f.round(3) # => -12345.679
When ndigits
is negative, returns an integer with at least ndigits.abs
trailing zeros:
f = 12345.6789 f.round(0) # => 12346 f.round(-3) # => 12000 f = -12345.6789 f.round(0) # => -12346 f.round(-3) # => -12000
If keyword argument half
is given, and self
is equidistant from the two candidate values, the rounding is according to the given half
value:
:up
or nil
: round away from zero:
2.5.round(half: :up) # => 3 3.5.round(half: :up) # => 4 (-2.5).round(half: :up) # => -3
:down
: round toward zero:
2.5.round(half: :down) # => 2 3.5.round(half: :down) # => 3 (-2.5).round(half: :down) # => -2
:even
: round toward the candidate whose last nonzero digit is even:
2.5.round(half: :even) # => 2 3.5.round(half: :even) # => 4 (-2.5).round(half: :even) # => -2
Raises and exception if the value for half
is invalid.
Related: Float#truncate
.
Returns a string containing a representation of self
; depending of the value of self
, the string representation may contain:
A fixed-point number.
A number in “scientific notation” (containing an exponent).
‘Infinity’.
‘-Infinity’.
‘NaN’ (indicating not-a-number).
3.14.to_s # => “3.14” (10.1**50).to_s # => “1.644631821843879e+50” (10.1**500).to_s # => “Infinity” (-10.1**500).to_s # => “-Infinity” (0.0/0.0).to_s # => “NaN”
Returns true
if self
is greater than 0, false
otherwise.
Returns true
if self
is less than 0, false
otherwise.
Removes the directory at dirpath
from the underlying file system:
Dir.rmdir('foo') # => 0
Raises an exception if the directory is not empty.
Returns the last access time for the named file as a Time
object.
file_name can be an IO
object.
File.atime("testfile") #=> Wed Apr 09 08:51:48 CDT 2003
Returns the modification time for the named file as a Time
object.
file_name can be an IO
object.
File.mtime("testfile") #=> Tue Apr 08 12:58:04 CDT 2003
Returns the birth time for the named file.
file_name can be an IO
object.
File.birthtime("testfile") #=> Wed Apr 09 08:53:13 CDT 2003
If the platform doesn’t have birthtime, raises NotImplementedError
.
Sets the access and modification times of each named file to the first two arguments. If a file is a symlink, this method acts upon its referent rather than the link itself; for the inverse behavior see File.lutime
. Returns the number of file names in the argument list.
Sets the access and modification times of each named file to the first two arguments. If a file is a symlink, this method acts upon the link itself as opposed to its referent; for the inverse behavior, see File.utime
. Returns the number of file names in the argument list.
Deletes the named files, returning the number of names passed as arguments. Raises an exception on any error. Since the underlying implementation relies on the unlink(2)
system call, the type of exception raised depends on its error type (see linux.die.net/man/2/unlink) and has the form of e.g. Errno::ENOENT.
See also Dir::rmdir
.