Returns true
if filepath
points to a block device, false
otherwise:
File.blockdev?('/dev/sda1') # => true File.blockdev?(File.new('t.tmp')) # => false
Returns a Digest
subclass by name
in a thread-safe manner even when on-demand loading is involved.
require 'digest' Digest("MD5") # => Digest::MD5 Digest(:SHA256) # => Digest::SHA256 Digest(:Foo) # => LoadError: library not found for class Digest::Foo -- digest/foo
Returns the result of invoking exception.to_s
. Normally this returns the exception’s message or name.
Return the receiver associated with this KeyError
exception.
Return the receiver associated with this NameError
exception.
Return the receiver associated with this FrozenError
exception.
Return this SystemCallError’s error number.
Registers _filename_ to be loaded (using Kernel::require) the first time that _const_ (which may be a String or a symbol) is accessed in the namespace of _mod_. module A end A.autoload(:B, "b") A::B.doit # autoloads "b"
If const in mod is defined as autoload, the file name to be loaded is replaced with filename. If const is defined but not as autoload, does nothing.
Returns filename to be loaded if name is registered as autoload
in the namespace of mod or one of its ancestors.
module A end A.autoload(:B, "b") A.autoload?(:B) #=> "b"
If inherit
is false, the lookup only checks the autoloads in the receiver:
class A autoload :CONST, "const.rb" end class B < A end B.autoload?(:CONST) #=> "const.rb", found in A (ancestor) B.autoload?(:CONST, false) #=> nil, not found in B itself
Internal method used to provide marshalling support. See the Marshal
module.
Returns the remainder from dividing by the value.
x.remainder(y) means x-y*(x/y).truncate
Return the largest integer less than or equal to the value, as a BigDecimal
.
BigDecimal('3.14159').floor #=> 3 BigDecimal('-9.1').floor #=> -10
If n is specified and positive, the fractional part of the result has no more than that many digits.
If n is specified and negative, at least that many digits to the left of the decimal point will be 0 in the result.
BigDecimal('3.14159').floor(3) #=> 3.141 BigDecimal('13345.234').floor(-2) #=> 13300.0
Returns the value raised to the power of n.
Note that n must be an Integer
.
Also available as the operator **.
Returns True if the value is zero.
Returns self if the value is non-zero, nil otherwise.
The coerce method provides support for Ruby type coercion. It is not enabled by default.
This means that binary operations like + * / or - can often be performed on a BigDecimal
and an object of another type, if the other object can be coerced into a BigDecimal
value.
e.g.
a = BigDecimal("1.0") b = a / 2.0 #=> 0.5
Note that coercing a String
to a BigDecimal
is not supported by default; it requires a special compile-time option when building Ruby.
Returns the numerator.
Rational(7).numerator #=> 7 Rational(7, 1).numerator #=> 7 Rational(9, -4).numerator #=> -9 Rational(-2, -10).numerator #=> 1
Returns the largest number less than or equal to rat
with a precision of ndigits
decimal digits (default: 0).
When the precision is negative, the returned value is an integer with at least ndigits.abs
trailing zeros.
Returns a rational when ndigits
is positive, otherwise returns an integer.
Rational(3).floor #=> 3 Rational(2, 3).floor #=> 0 Rational(-3, 2).floor #=> -2 # decimal - 1 2 3 . 4 5 6 # ^ ^ ^ ^ ^ ^ # precision -3 -2 -1 0 +1 +2 Rational('-123.456').floor(+1).to_f #=> -123.5 Rational('-123.456').floor(-1) #=> -130
This method is an alias for http_header
, when HTML5
tag maker is inactive.
NOTE: use http_header
to create HTTP header blocks, this alias is only provided for backwards compatibility.
Using header
with the HTML5
tag maker will create a <header> element.
Returns a new Date object constructed from the arguments.
Argument cwyear
gives the year, and should be an integer.
Argument cweek
gives the index of the week within the year, and should be in range (1..53) or (-53..-1); in some years, 53 or -53 will be out-of-range; if negative, counts backward from the end of the year:
Date.commercial(2022, 1, 1).to_s # => "2022-01-03" Date.commercial(2022, 52, 1).to_s # => "2022-12-26"
Argument cwday
gives the indes of the weekday within the week, and should be in range (1..7) or (-7..-1); 1 or -7 is Monday; if negative, counts backward from the end of the week:
Date.commercial(2022, 1, 1).to_s # => "2022-01-03" Date.commercial(2022, 1, -7).to_s # => "2022-01-03"
When cweek
is 1:
If January 1 is a Friday, Saturday, or Sunday, the first week begins in the week after:
Date::ABBR_DAYNAMES[Date.new(2023, 1, 1).wday] # => "Sun" Date.commercial(2023, 1, 1).to_s # => "2023-01-02" Date.commercial(2023, 1, 7).to_s # => "2023-01-08"
Otherwise, the first week is the week of January 1, which may mean some of the days fall on the year before:
Date::ABBR_DAYNAMES[Date.new(2020, 1, 1).wday] # => "Wed" Date.commercial(2020, 1, 1).to_s # => "2019-12-30" Date.commercial(2020, 1, 7).to_s # => "2020-01-05"
See argument start.
Related: Date.jd
, Date.new
, Date.ordinal
.
Creates a DateTime
object denoting the given week date.
DateTime.commercial(2001) #=> #<DateTime: 2001-01-01T00:00:00+00:00 ...> DateTime.commercial(2002) #=> #<DateTime: 2001-12-31T00:00:00+00:00 ...> DateTime.commercial(2001,5,6,4,5,6,'+7') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
Like Time.utc
, except that the returned Time
object has the local timezone, not the UTC timezone:
# With seven arguments. Time.local(0, 1, 2, 3, 4, 5, 6) # => 0000-01-02 03:04:05.000006 -0600 # With exactly ten arguments. Time.local(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) # => 0005-04-03 02:01:00 -0600
With no argument given:
Returns self
if self
is a local time.
Otherwise returns a new Time
in the user’s local timezone:
t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC t.localtime # => 2000-01-01 14:15:01 -0600
With argument zone
given, returns the new Time
object created by converting self
to the given time zone:
t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC t.localtime("-09:00") # => 2000-01-01 11:15:01 -0900
For forms of argument zone
, see Timezone Specifiers.