Returns the change time for the named file (the time at which directory information about the file was changed, not the file itself).
file_name can be an IO
object.
Note that on Windows (NTFS), returns creation time (birth time).
File.ctime("testfile") #=> Wed Apr 09 08:53:13 CDT 2003
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.
Truncates the file file_name to be at most integer bytes long. Not available on all platforms.
f = File.new("out", "w") f.write("1234567890") #=> 10 f.close #=> nil File.truncate("out", 5) #=> 0 File.size("out") #=> 5
Same as IO#stat
, but does not follow the last symbolic link. Instead, reports on the link itself.
File.symlink("testfile", "link2test") #=> 0 File.stat("testfile").size #=> 66 f = File.new("link2test") f.lstat.size #=> 8 f.stat.size #=> 66
Returns the modification time for file.
File.new("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
Returns the change time for file (that is, the time directory information about the file was changed, not the file itself).
Note that on Windows (NTFS), returns creation time (birth time).
File.new("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
Truncates file to at most integer bytes. The file must be opened for writing. Not available on all platforms.
f = File.new("out", "w") f.syswrite("1234567890") #=> 10 f.truncate(5) #=> 0 f.close() #=> nil File.size("out") #=> 5
Returns a replicated encoding of enc whose name is name. The new encoding should have the same byte structure of enc. If name is used by another encoding, raise ArgumentError
.
Returns the result of invoking exception.to_s
. Normally this returns the exception’s message or name.
Return the status value associated with this system exit.
Return the matchee associated with this NoMatchingPatternKeyError
exception.
The first form is equivalent to attr_reader
. The second form is equivalent to attr_accessor(name)
but deprecated. The last form is equivalent to attr_reader(name)
but deprecated. Returns an array of defined method names as symbols.
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 True if the value is Not a Number.
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 true
if rat
is less than 0.
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
Parse an HTTP query string into a hash of key=>value pairs.
params = CGI.parse("query_string") # {"name1" => ["value1", "value2", ...], # "name2" => ["value1", "value2", ...], ... }
Creates a date object denoting the given ordinal date.
The day of year should be a negative or a positive number (as a relative day from the end of year when negative). It should not be zero.
Date.ordinal(2001) #=> #<Date: 2001-01-01 ...> Date.ordinal(2001,34) #=> #<Date: 2001-02-03 ...> Date.ordinal(2001,-1) #=> #<Date: 2001-12-31 ...>
Creates a date object denoting the given week date.
The week and the day of week should be a negative or a positive number (as a relative week/day from the end of year/week when negative). They should not be zero.
Date.commercial(2001) #=> #<Date: 2001-01-01 ...> Date.commercial(2002) #=> #<Date: 2001-12-31 ...> Date.commercial(2001,5,6) #=> #<Date: 2001-02-03 ...>
Parses the given representation of date and time with the given template, and returns a hash of parsed elements. _strptime does not support specification of flags and width unlike strftime.
Date._strptime('2001-02-03', '%Y-%m-%d') #=> {:year=>2001, :mon=>2, :mday=>3}
See also strptime(3) and strftime
.
Parses the given representation of date and time with the given template, and creates a date object. strptime does not support specification of flags and width unlike strftime.
Date.strptime('2001-02-03', '%Y-%m-%d') #=> #<Date: 2001-02-03 ...> Date.strptime('03-02-2001', '%d-%m-%Y') #=> #<Date: 2001-02-03 ...> Date.strptime('2001-034', '%Y-%j') #=> #<Date: 2001-02-03 ...> Date.strptime('2001-W05-6', '%G-W%V-%u') #=> #<Date: 2001-02-03 ...> Date.strptime('2001 04 6', '%Y %U %w') #=> #<Date: 2001-02-03 ...> Date.strptime('2001 05 6', '%Y %W %u') #=> #<Date: 2001-02-03 ...> Date.strptime('sat3feb01', '%a%d%b%y') #=> #<Date: 2001-02-03 ...>
See also strptime(3) and strftime
.
Parses the given representation of date and time, and returns a hash of parsed elements.
This method *does not* function as a validator. If the input string does not match valid formats strictly, you may get a cryptic result. Should consider to use ‘Date._strptime` or `DateTime._strptime` instead of this method as possible.
If the optional second argument is true and the detected year is in the range “00” to “99”, considers the year a 2-digit form and makes it full.
Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
Raise an ArgumentError
when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.
Parses the given representation of date and time, and creates a date object.
This method *does not* function as a validator. If the input string does not match valid formats strictly, you may get a cryptic result. Should consider to use ‘Date.strptime` instead of this method as possible.
If the optional second argument is true and the detected year is in the range “00” to “99”, considers the year a 2-digit form and makes it full.
Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...> Date.parse('20010203') #=> #<Date: 2001-02-03 ...> Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
Raise an ArgumentError
when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.