With no arguments, sets the default visibility for subsequently defined methods to private. With arguments, sets the named methods to have private visibility. String
arguments are converted to symbols. An Array
of Symbols and/or Strings is also accepted. If a single argument is passed, it is returned. If no argument is passed, nil is returned. If multiple arguments are passed, the arguments are returned as an array.
module Mod def a() end def b() end private def c() end private :a end Mod.private_instance_methods #=> [:a, :c]
Note that to show a private method on RDoc
, use :doc:
.
Returns the remainder from dividing by the value.
x.remainder(y) means x-y*(x/y).truncate
Returns a string representation of self.
BigDecimal("1234.5678").inspect #=> "0.12345678e4"
Returns True if the value is finite (not NaN or infinite).
Truncate to the nearest integer (by default), returning the result as a BigDecimal
.
BigDecimal('3.14159').truncate #=> 3 BigDecimal('8.7').truncate #=> 8 BigDecimal('-9.9').truncate #=> -9
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').truncate(3) #=> 3.141 BigDecimal('13345.234').truncate(-2) #=> 13300.0
Returns the denominator (always positive).
Rational(7).denominator #=> 1 Rational(7, 1).denominator #=> 1 Rational(9, -4).denominator #=> 4 Rational(-2, -10).denominator #=> 5
Returns rat
truncated (toward zero) to 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).truncate #=> 3 Rational(2, 3).truncate #=> 0 Rational(-3, 2).truncate #=> -1 # decimal - 1 2 3 . 4 5 6 # ^ ^ ^ ^ ^ ^ # precision -3 -2 -1 0 +1 +2 Rational('-123.456').truncate(+1).to_f #=> -123.4 Rational('-123.456').truncate(-1) #=> -120
Returns the value as a string for inspection.
Rational(2).inspect #=> "(2/1)" Rational(-8, 6).inspect #=> "(-4/3)" Rational('1/2').inspect #=> "(1/2)"
Synonym for $stdout.
Returns a new Date object formed fom the arguments.
With no arguments, returns the date for January 1, -4712:
Date.ordinal.to_s # => "-4712-01-01"
With argument year
, returns the date for January 1 of that year:
Date.ordinal(2001).to_s # => "2001-01-01" Date.ordinal(-2001).to_s # => "-2001-01-01"
With positive argument yday
== n
, returns the date for the nth
day of the given year:
Date.ordinal(2001, 14).to_s # => "2001-01-14"
With negative argument yday
, counts backward from the end of the year:
Date.ordinal(2001, -14).to_s # => "2001-12-18"
Raises an exception if yday
is zero or out of range.
See argument start.
Returns true
if self
is a Friday, false
otherwise.
Returns true
if the date is on or after the date of calendar reform, false
otherwise:
Date.new(1582, 10, 15).gregorian? # => true (Date.new(1582, 10, 15) - 1).gregorian? # => false
Returns the Julian start date for calendar reform; if not an infinity, the returned value is suitable for passing to Date#jd
:
d = Date.new(2001, 2, 3, Date::ITALY) s = d.start # => 2299161.0 Date.jd(s).to_s # => "1582-10-15" d = Date.new(2001, 2, 3, Date::ENGLAND) s = d.start # => 2361222.0 Date.jd(s).to_s # => "1752-09-14" Date.new(2001, 2, 3, Date::GREGORIAN).start # => -Infinity Date.new(2001, 2, 3, Date::JULIAN).start # => Infinity
See argument start.
Equivalent to Date#new_start
with argument Date::ENGLAND
.
Equivalent to Date#new_start
with argument Date::GREGORIAN
.
Calls the block with specified dates; returns self
.
The first date
is self
.
Each successive date
is date + step
, where step
is the numeric step size in days.
The last date is the last one that is before or equal to limit
, which should be a Date object.
Example:
limit = Date.new(2001, 12, 31) Date.new(2001).step(limit){|date| p date.to_s if date.mday == 31 }
Output:
"2001-01-31" "2001-03-31" "2001-05-31" "2001-07-31" "2001-08-31" "2001-10-31" "2001-12-31"
Returns an Enumerator
if no block is given.
Returns a string representation of self
:
Date.new(2001, 2, 3).inspect # => "#<Date: 2001-02-03 ((2451944j,0s,0n),+0s,2299161j)>"
Creates a DateTime
object denoting the given ordinal date.
DateTime.ordinal(2001,34) #=> #<DateTime: 2001-02-03T00:00:00+00:00 ...> DateTime.ordinal(2001,34,4,5,6,'+7') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...> DateTime.ordinal(2001,-332,-20,-55,-54,'+7') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
Returns a string representation of self
with subseconds:
t = Time.new(2000, 12, 31, 23, 59, 59, 0.5) t.inspect # => "2000-12-31 23:59:59.5 +000001"
Related: Time#ctime
, Time#to_s
:
t.ctime # => "Sun Dec 31 23:59:59 2000" t.to_s # => "2000-12-31 23:59:59 +0000"
Returns the integer minute of the hour for self
, in range (0..59):
t = Time.new(2000, 1, 2, 3, 4, 5, 6) # => 2000-01-02 03:04:05 +000006 t.min # => 4
Returns true
if self
is in daylight saving time, false
otherwise:
t = Time.local(2000, 1, 1) # => 2000-01-01 00:00:00 -0600 t.zone # => "Central Standard Time" t.dst? # => false t = Time.local(2000, 7, 1) # => 2000-07-01 00:00:00 -0500 t.zone # => "Central Daylight Time" t.dst? # => true
Returns true
if self
is in daylight saving time, false
otherwise:
t = Time.local(2000, 1, 1) # => 2000-01-01 00:00:00 -0600 t.zone # => "Central Standard Time" t.dst? # => false t = Time.local(2000, 7, 1) # => 2000-07-01 00:00:00 -0500 t.zone # => "Central Daylight Time" t.dst? # => true
Returns true
if self
represents a Friday, false
otherwise:
t = Time.utc(2000, 1, 7) # => 2000-01-07 00:00:00 UTC t.friday? # => true
Related: Time#saturday?
, Time#sunday?
, Time#monday?
.