Returns the previous representable floating-point number.
(-Float::MAX).prev_float and (-Float::INFINITY).prev_float is -Float::INFINITY.
Float::NAN.prev_float is Float::NAN
.
For example:
p 0.01.prev_float #=> 0.009999999999999998 p 1.0.prev_float #=> 0.9999999999999999 p 100.0.prev_float #=> 99.99999999999999 p 0.01 - 0.01.prev_float #=> 1.734723475976807e-18 p 1.0 - 1.0.prev_float #=> 1.1102230246251565e-16 p 100.0 - 100.0.prev_float #=> 1.4210854715202004e-14 f = 0.01; 20.times { printf "%-20a %s\n", f, f.to_s; f = f.prev_float } #=> 0x1.47ae147ae147bp-7 0.01 # 0x1.47ae147ae147ap-7 0.009999999999999998 # 0x1.47ae147ae1479p-7 0.009999999999999997 # 0x1.47ae147ae1478p-7 0.009999999999999995 # 0x1.47ae147ae1477p-7 0.009999999999999993 # 0x1.47ae147ae1476p-7 0.009999999999999992 # 0x1.47ae147ae1475p-7 0.00999999999999999 # 0x1.47ae147ae1474p-7 0.009999999999999988 # 0x1.47ae147ae1473p-7 0.009999999999999986 # 0x1.47ae147ae1472p-7 0.009999999999999985 # 0x1.47ae147ae1471p-7 0.009999999999999983 # 0x1.47ae147ae147p-7 0.009999999999999981 # 0x1.47ae147ae146fp-7 0.00999999999999998 # 0x1.47ae147ae146ep-7 0.009999999999999978 # 0x1.47ae147ae146dp-7 0.009999999999999976 # 0x1.47ae147ae146cp-7 0.009999999999999974 # 0x1.47ae147ae146bp-7 0.009999999999999972 # 0x1.47ae147ae146ap-7 0.00999999999999997 # 0x1.47ae147ae1469p-7 0.009999999999999969 # 0x1.47ae147ae1468p-7 0.009999999999999967
Returns the path parameter passed to dir’s constructor.
d = Dir.new("..") d.path #=> ".."
Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless dir_string
is given, in which case it will be used as the starting point. The given pathname may start with a “~
”, which expands to the process owner’s home directory (the environment variable HOME
must be set correctly). “~
user” expands to the named user’s home directory.
File.expand_path("~oracle/bin") #=> "/home/oracle/bin"
A simple example of using dir_string
is as follows.
File.expand_path("ruby", "/usr/bin") #=> "/usr/bin/ruby"
A more complex example which also resolves parent directory is as follows. Suppose we are in bin/mygem and want the absolute path of lib/mygem.rb.
File.expand_path("../../lib/mygem.rb", __FILE__) #=> ".../path/to/project/lib/mygem.rb"
So first it resolves the parent of __FILE__, that is bin/, then go to the parent, the root of the project and appends lib/mygem.rb
.
Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless dir_string is given, in which case it will be used as the starting point. If the given pathname starts with a “~
” it is NOT expanded, it is treated as a normal directory name.
File.absolute_path("~oracle/bin") #=> "<relative_path>/~oracle/bin"
Returns the pathname used to create file as a string. Does not normalize the name.
File.new("testfile").path #=> "testfile" File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx"
Returns whether ASCII-compatible or not.
Encoding::UTF_8.ascii_compatible? #=> true Encoding::UTF_16BE.ascii_compatible? #=> false
Returns any backtrace associated with the exception. This method is similar to Exception#backtrace
, but the backtrace is an array of Thread::Backtrace::Location
.
Now, this method is not affected by Exception#set_backtrace()
.
Deserializes JSON
string by constructing new Exception
object with message m
and backtrace b
serialized with to_json
When this module is included in another, Ruby calls append_features
in this module, passing it the receiving module in mod. Ruby’s default implementation is to add the constants, methods, and module variables of this module to mod if this module has not already been added to mod or one of its ancestors. See also Module#include
.
When this module is prepended in another, Ruby calls prepend_features
in this module, passing it the receiving module in mod. Ruby’s default implementation is to overlay the constants, methods, and module variables of this module to mod if this module has not already been added to mod or one of its ancestors. See also Module#prepend
.
Creates instance variables and corresponding methods that return the value of each instance variable. Equivalent to calling “attr
:name” on each name in turn. String arguments are converted to symbols.
Creates an accessor method to allow assignment to the attribute symbol.id2name
. String arguments are converted to symbols.
Defines a named attribute for this module, where the name is symbol.id2name
, creating an instance variable (@name
) and a corresponding access method to read it. Also creates a method called name=
to set the attribute. String arguments are converted to symbols.
module Mod attr_accessor(:one, :two) end Mod.instance_methods.sort #=> [:one, :one=, :two, :two=]
Makes a list of existing constants private.
Makes a list of existing constants deprecated.
Deserializes JSON
string by converting numerator value n
, denominator value d
, to a Rational
object.
Returns true if the given calendar date is valid, and false if not.
Date.valid_date?(2001,2,3) #=> true Date.valid_date?(2001,2,29) #=> false
Returns self.
Returns a DateTime
object which denotes self.
Deserializes JSON
string by converting Julian year y
, month m
, day d
and Day of Calendar Reform sg
to Date
.
Returns a Date
object which denotes self.
Returns self.
Deserializes JSON
string by converting year y
, month m
, day d
, hour H
, minute M
, second S
, offset of
and Day of Calendar Reform sg
to DateTime
.