diff --git a/.github/workflows/comments.yml b/.github/workflows/comments.yml index 6fea1e44d..d24d9dcd7 100644 --- a/.github/workflows/comments.yml +++ b/.github/workflows/comments.yml @@ -13,7 +13,7 @@ jobs: container: image: rubylang/ruby:3.2-dev-focal env: - RUBY_COMMIT: v3_3_0_rc1 + RUBY_COMMIT: v3_3_0 steps: - uses: actions/checkout@v4 - name: Install dependencies diff --git a/core/complex.rbs b/core/complex.rbs index a7333e5c7..b251a051b 100644 --- a/core/complex.rbs +++ b/core/complex.rbs @@ -36,6 +36,10 @@ # *argument* parts; see [Complex polar # plane](https://en.wikipedia.org/wiki/Complex_number#Polar_complex_plane). # +# In this class, the argument part in expressed +# [radians](https://en.wikipedia.org/wiki/Radian) (not +# [degrees](https://en.wikipedia.org/wiki/Degree_(angle))). +# # You can create a Complex object from polar coordinates with: # # * Method Complex.polar. @@ -62,7 +66,7 @@ class Complex < Numeric # --> # Returns a new Complex object formed from the arguments, each of which must be # an instance of Numeric, or an instance of one of its subclasses: Complex, - # Float, Integer, Rational; see [Polar + # Float, Integer, Rational. Argument `arg` is given in radians; see [Polar # Coordinates](rdoc-ref:Complex@Polar+Coordinates): # # Complex.polar(3) # => (3+0i) @@ -109,40 +113,40 @@ class Complex < Numeric # - # Performs multiplication. + # Returns the product of `self` and `numeric`: # - # Complex(2, 3) * Complex(2, 3) #=> (-5+12i) - # Complex(900) * Complex(1) #=> (900+0i) - # Complex(-2, 9) * Complex(-9, 2) #=> (0-85i) - # Complex(9, 8) * 4 #=> (36+32i) - # Complex(20, 9) * 9.8 #=> (196.0+88.2i) + # Complex(2, 3) * Complex(2, 3) # => (-5+12i) + # Complex(900) * Complex(1) # => (900+0i) + # Complex(-2, 9) * Complex(-9, 2) # => (0-85i) + # Complex(9, 8) * 4 # => (36+32i) + # Complex(20, 9) * 9.8 # => (196.0+88.2i) # def *: (Numeric) -> Complex # - # Performs exponentiation. + # Returns `self` raised to power `numeric`: # - # Complex('i') ** 2 #=> (-1+0i) - # Complex(-8) ** Rational(1, 3) #=> (1.0000000000000002+1.7320508075688772i) + # Complex('i') ** 2 # => (-1+0i) + # Complex(-8) ** Rational(1, 3) # => (1.0000000000000002+1.7320508075688772i) # def **: (Numeric) -> Complex # - # Performs addition. + # Returns the sum of `self` and `numeric`: # - # Complex(2, 3) + Complex(2, 3) #=> (4+6i) - # Complex(900) + Complex(1) #=> (901+0i) - # Complex(-2, 9) + Complex(-9, 2) #=> (-11+11i) - # Complex(9, 8) + 4 #=> (13+8i) - # Complex(20, 9) + 9.8 #=> (29.8+9i) + # Complex(2, 3) + Complex(2, 3) # => (4+6i) + # Complex(900) + Complex(1) # => (901+0i) + # Complex(-2, 9) + Complex(-9, 2) # => (-11+11i) + # Complex(9, 8) + 4 # => (13+8i) + # Complex(20, 9) + 9.8 # => (29.8+9i) # def +: (Numeric) -> Complex @@ -150,40 +154,40 @@ class Complex < Numeric # - # Performs subtraction. + # Returns the difference of `self` and `numeric`: # - # Complex(2, 3) - Complex(2, 3) #=> (0+0i) - # Complex(900) - Complex(1) #=> (899+0i) - # Complex(-2, 9) - Complex(-9, 2) #=> (7+7i) - # Complex(9, 8) - 4 #=> (5+8i) - # Complex(20, 9) - 9.8 #=> (10.2+9i) + # Complex(2, 3) - Complex(2, 3) # => (0+0i) + # Complex(900) - Complex(1) # => (899+0i) + # Complex(-2, 9) - Complex(-9, 2) # => (7+7i) + # Complex(9, 8) - 4 # => (5+8i) + # Complex(20, 9) - 9.8 # => (10.2+9i) # def -: (Numeric) -> Complex # - # Returns negation of the value. + # Returns the negation of `self`, which is the negation of each of its parts: # - # -Complex(1, 2) #=> (-1-2i) + # -Complex(1, 2) # => (-1-2i) + # -Complex(-1, -2) # => (1+2i) # def -@: () -> Complex # - # Performs division. + # Returns the quotient of `self` and `numeric`: # - # Complex(2, 3) / Complex(2, 3) #=> ((1/1)+(0/1)*i) - # Complex(900) / Complex(1) #=> ((900/1)+(0/1)*i) - # Complex(-2, 9) / Complex(-9, 2) #=> ((36/85)-(77/85)*i) - # Complex(9, 8) / 4 #=> ((9/4)+(2/1)*i) - # Complex(20, 9) / 9.8 #=> (2.0408163265306123+0.9183673469387754i) + # Complex(2, 3) / Complex(2, 3) # => ((1/1)+(0/1)*i) + # Complex(900) / Complex(1) # => ((900/1)+(0/1)*i) + # Complex(-2, 9) / Complex(-9, 2) # => ((36/85)-(77/85)*i) + # Complex(9, 8) / 4 # => ((9/4)+(2/1)*i) + # Complex(20, 9) / 9.8 # => (2.0408163265306123+0.9183673469387754i) # def /: (Numeric) -> Complex @@ -193,31 +197,38 @@ class Complex < Numeric # - # If `cmp`'s imaginary part is zero, and `object` is also a real number (or a - # Complex number where the imaginary part is zero), compare the real part of - # `cmp` to object. Otherwise, return nil. + # Returns: + # + # * `self.real <=> object.real` if both of the following are true: + # + # * `self.imag == 0`. + # * `object.imag == 0`. # Always true if object is numeric but not + # complex. + # + # + # * `nil` otherwise. + # # - # Complex(2, 3) <=> Complex(2, 3) #=> nil - # Complex(2, 3) <=> 1 #=> nil - # Complex(2) <=> 1 #=> 1 - # Complex(2) <=> 2 #=> 0 - # Complex(2) <=> 3 #=> -1 + # Examples: + # + # Complex(2) <=> 3 # => -1 + # Complex(2) <=> 2 # => 0 + # Complex(2) <=> 1 # => 1 + # Complex(2, 1) <=> 1 # => nil # self.imag not zero. + # Complex(1) <=> Complex(1, 1) # => nil # object.imag not zero. + # Complex(1) <=> 'Foo' # => nil # object.imag not defined. # def <=>: (untyped) -> Integer? # - # Returns true if cmp equals object numerically. + # Returns `true` if `self.real == object.real` and `self.imag == object.imag`: # - # Complex(2, 3) == Complex(2, 3) #=> true - # Complex(5) == 5 #=> true - # Complex(0) == 0.0 #=> true - # Complex('1/3') == 0.33 #=> false - # Complex('1/2') == '1/2' #=> false + # Complex(2, 3) == Complex(2.0, 3.0) # => true # def ==: (untyped) -> bool @@ -227,43 +238,66 @@ class Complex < Numeric # - # Returns the absolute part of its polar form. + # Returns the absolute value (magnitude) for `self`; see [polar + # coordinates](rdoc-ref:Complex@Polar+Coordinates): + # + # Complex.polar(-1, 0).abs # => 1.0 + # + # If `self` was created with [rectangular + # coordinates](rdoc-ref:Complex@Rectangular+Coordinates), the returned value is + # computed, and may be inexact: # - # Complex(-1).abs #=> 1 - # Complex(3.0, -4.0).abs #=> 5.0 + # Complex.rectangular(1, 1).abs # => 1.4142135623730951 # The square root of 2. # def abs: () -> Numeric # - # Returns square of the absolute value. + # Returns square of the absolute value (magnitude) for `self`; see [polar + # coordinates](rdoc-ref:Complex@Polar+Coordinates): # - # Complex(-1).abs2 #=> 1 - # Complex(3.0, -4.0).abs2 #=> 25.0 + # Complex.polar(2, 2).abs2 # => 4.0 + # + # If `self` was created with [rectangular + # coordinates](rdoc-ref:Complex@Rectangular+Coordinates), the returned value is + # computed, and may be inexact: + # + # Complex.rectangular(1.0/3, 1.0/3).abs2 # => 0.2222222222222222 # def abs2: () -> Numeric # - # Returns the angle part of its polar form. + # Returns the argument (angle) for `self` in radians; see [polar + # coordinates](rdoc-ref:Complex@Polar+Coordinates): + # + # Complex.polar(3, Math::PI/2).arg # => 1.57079632679489660 # - # Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966 + # If `self` was created with [rectangular + # coordinates](rdoc-ref:Complex@Rectangular+Coordinates), the returned value is + # computed, and may be inexact: + # + # Complex.polar(1, 1.0/3).arg # => 0.33333333333333326 # def angle: () -> Float # - # Returns the angle part of its polar form. + # Returns the argument (angle) for `self` in radians; see [polar + # coordinates](rdoc-ref:Complex@Polar+Coordinates): + # + # Complex.polar(3, Math::PI/2).arg # => 1.57079632679489660 + # + # If `self` was created with [rectangular + # coordinates](rdoc-ref:Complex@Rectangular+Coordinates), the returned value is + # computed, and may be inexact: # - # Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966 + # Complex.polar(1, 1.0/3).arg # => 0.33333333333333326 # alias arg angle @@ -272,30 +306,35 @@ class Complex < Numeric def coerce: (Numeric) -> [ Complex, Complex ] # - # Returns the complex conjugate. + # Returns the conjugate of `self`, `Complex.rect(self.imag, self.real)`: # - # Complex(1, 2).conjugate #=> (1-2i) + # Complex.rect(1, 2).conj # => (1-2i) # def conj: () -> Complex # - # Returns the complex conjugate. + # Returns the conjugate of `self`, `Complex.rect(self.imag, self.real)`: # - # Complex(1, 2).conjugate #=> (1-2i) + # Complex.rect(1, 2).conj # => (1-2i) # def conjugate: () -> Complex # - # Returns the denominator (lcm of both denominator - real and imag). + # Returns the denominator of `self`, which is the [least common + # multiple](https://en.wikipedia.org/wiki/Least_common_multiple) of + # `self.real.denominator` and `self.imag.denominator`: # - # See numerator. + # Complex.rect(Rational(1, 2), Rational(2, 3)).denominator # => 6 + # + # Note that `n.denominator` of a non-rational numeric is `1`. + # + # Related: Complex#numerator. # def denominator: () -> Integer @@ -309,20 +348,25 @@ class Complex < Numeric # - # Performs division as each part is a float, never returns a float. + # Returns `Complex(self.real/numeric, self.imag/numeric)`: # - # Complex(11, 22).fdiv(3) #=> (3.6666666666666665+7.333333333333333i) + # Complex(11, 22).fdiv(3) # => (3.6666666666666665+7.333333333333333i) # def fdiv: (Numeric) -> Complex # - # Returns `true` if `cmp`'s real and imaginary parts are both finite numbers, - # otherwise returns `false`. + # Returns `true` if both `self.real.finite?` and `self.imag.finite?` are true, + # `false` otherwise: + # + # Complex(1, 1).finite? # => true + # Complex(Float::INFINITY, 0).finite? # => false + # + # Related: Numeric#finite?, Float#finite?. # def finite?: () -> bool @@ -330,68 +374,91 @@ class Complex < Numeric # + # Returns the integer hash value for `self`. + # + # Two Complex objects created from the same values will have the same hash value + # (and will compare using #eql?): + # + # Complex(1, 2).hash == Complex(1, 2).hash # => true # def hash: () -> Integer def i: () -> bot # - # Returns the imaginary part. + # Returns the imaginary value for `self`: # # Complex(7).imaginary #=> 0 # Complex(9, -4).imaginary #=> -4 # + # If `self` was created with [polar + # coordinates](rdoc-ref:Complex@Polar+Coordinates), the returned value is + # computed, and may be inexact: + # + # Complex.polar(1, Math::PI/4).imag # => 0.7071067811865476 # Square root of 2. + # def imag: () -> Numeric # - # Returns the imaginary part. + # Returns the imaginary value for `self`: # # Complex(7).imaginary #=> 0 # Complex(9, -4).imaginary #=> -4 # + # If `self` was created with [polar + # coordinates](rdoc-ref:Complex@Polar+Coordinates), the returned value is + # computed, and may be inexact: + # + # Complex.polar(1, Math::PI/4).imag # => 0.7071067811865476 # Square root of 2. + # def imaginary: () -> Numeric # - # Returns `1` if `cmp`'s real or imaginary part is an infinite number, otherwise - # returns `nil`. + # Returns `1` if either `self.real.infinite?` or `self.imag.infinite?` is true, + # `nil` otherwise: # - # For example: + # Complex(Float::INFINITY, 0).infinite? # => 1 + # Complex(1, 1).infinite? # => nil # - # (1+1i).infinite? #=> nil - # (Float::INFINITY + 1i).infinite? #=> 1 + # Related: Numeric#infinite?, Float#infinite?. # def infinite?: () -> Integer? # - # Returns the value as a string for inspection. + # Returns a string representation of `self`: # - # Complex(2).inspect #=> "(2+0i)" - # Complex('-8/6').inspect #=> "((-4/3)+0i)" - # Complex('1/2i').inspect #=> "(0+(1/2)*i)" - # Complex(0, Float::INFINITY).inspect #=> "(0+Infinity*i)" - # Complex(Float::NAN, Float::NAN).inspect #=> "(NaN+NaN*i)" + # Complex(2).inspect # => "(2+0i)" + # Complex('-8/6').inspect # => "((-4/3)+0i)" + # Complex('1/2i').inspect # => "(0+(1/2)*i)" + # Complex(0, Float::INFINITY).inspect # => "(0+Infinity*i)" + # Complex(Float::NAN, Float::NAN).inspect # => "(NaN+NaN*i)" # def inspect: () -> String def integer?: () -> bool # - # Returns the absolute part of its polar form. + # Returns the absolute value (magnitude) for `self`; see [polar + # coordinates](rdoc-ref:Complex@Polar+Coordinates): + # + # Complex.polar(-1, 0).abs # => 1.0 # - # Complex(-1).abs #=> 1 - # Complex(3.0, -4.0).abs #=> 5.0 + # If `self` was created with [rectangular + # coordinates](rdoc-ref:Complex@Rectangular+Coordinates), the returned value is + # computed, and may be inexact: + # + # Complex.rectangular(1, 1).abs # => 1.4142135623730951 # The square root of 2. # alias magnitude abs @@ -403,39 +470,54 @@ class Complex < Numeric # - # Returns the numerator. + # Returns the Complex object created from the numerators of the real and + # imaginary parts of `self`, after converting each part to the [lowest common + # denominator](https://en.wikipedia.org/wiki/Lowest_common_denominator) of the + # two: # - # 1 2 3+4i <- numerator - # - + -i -> ---- - # 2 3 6 <- denominator + # c = Complex(Rational(2, 3), Rational(3, 4)) # => ((2/3)+(3/4)*i) + # c.numerator # => (8+9i) # - # c = Complex('1/2+2/3i') #=> ((1/2)+(2/3)*i) - # n = c.numerator #=> (3+4i) - # d = c.denominator #=> 6 - # n / d #=> ((1/2)+(2/3)*i) - # Complex(Rational(n.real, d), Rational(n.imag, d)) - # #=> ((1/2)+(2/3)*i) + # In this example, the lowest common denominator of the two parts is 12; the two + # converted parts may be thought of as Rational(8, 12) and Rational(9, 12), + # whose numerators, respectively, are 8 and 9; so the returned value of + # `c.numerator` is `Complex(8, 9)`. # - # See denominator. + # Related: Complex#denominator. # def numerator: () -> Complex # - # Returns the angle part of its polar form. + # Returns the argument (angle) for `self` in radians; see [polar + # coordinates](rdoc-ref:Complex@Polar+Coordinates): + # + # Complex.polar(3, Math::PI/2).arg # => 1.57079632679489660 + # + # If `self` was created with [rectangular + # coordinates](rdoc-ref:Complex@Rectangular+Coordinates), the returned value is + # computed, and may be inexact: # - # Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966 + # Complex.polar(1, 1.0/3).arg # => 0.33333333333333326 # alias phase angle # - # Returns an array; [cmp.abs, cmp.arg]. + # Returns the array `[self.abs, self.arg]`: # - # Complex(1, 2).polar #=> [2.23606797749979, 1.1071487177940904] + # Complex.polar(1, 2).polar # => [1.0, 2.0] + # + # See [Polar Coordinates](rdoc-ref:Complex@Polar+Coordinates). + # + # If `self` was created with [rectangular + # coordinates](rdoc-ref:Complex@Rectangular+Coordinates), the returned value is + # computed, and may be inexact: + # + # Complex.rect(1, 1).polar # => [1.4142135623730951, 0.7853981633974483] # def polar: () -> [ Numeric, Float ] @@ -443,51 +525,73 @@ class Complex < Numeric # - # Performs division. + # Returns the quotient of `self` and `numeric`: # - # Complex(2, 3) / Complex(2, 3) #=> ((1/1)+(0/1)*i) - # Complex(900) / Complex(1) #=> ((900/1)+(0/1)*i) - # Complex(-2, 9) / Complex(-9, 2) #=> ((36/85)-(77/85)*i) - # Complex(9, 8) / 4 #=> ((9/4)+(2/1)*i) - # Complex(20, 9) / 9.8 #=> (2.0408163265306123+0.9183673469387754i) + # Complex(2, 3) / Complex(2, 3) # => ((1/1)+(0/1)*i) + # Complex(900) / Complex(1) # => ((900/1)+(0/1)*i) + # Complex(-2, 9) / Complex(-9, 2) # => ((36/85)-(77/85)*i) + # Complex(9, 8) / 4 # => ((9/4)+(2/1)*i) + # Complex(20, 9) / 9.8 # => (2.0408163265306123+0.9183673469387754i) # def quo: (Numeric) -> Complex # - # Returns the value as a rational if possible (the imaginary part should be - # exactly zero). + # Returns a Rational object whose value is exactly or approximately equivalent + # to that of `self.real`. + # + # With no argument `epsilon` given, returns a Rational object whose value is + # exactly equal to that of `self.real.rationalize`: + # + # Complex(1, 0).rationalize # => (1/1) + # Complex(1, Rational(0, 1)).rationalize # => (1/1) + # Complex(3.14159, 0).rationalize # => (314159/100000) # - # Complex(1.0/3, 0).rationalize #=> (1/3) - # Complex(1, 0.0).rationalize # RangeError - # Complex(1, 2).rationalize # RangeError + # With argument `epsilon` given, returns a Rational object whose value is + # exactly or approximately equal to that of `self.real` to the given precision: # - # See to_r. + # Complex(3.14159, 0).rationalize(0.1) # => (16/5) + # Complex(3.14159, 0).rationalize(0.01) # => (22/7) + # Complex(3.14159, 0).rationalize(0.001) # => (201/64) + # Complex(3.14159, 0).rationalize(0.0001) # => (333/106) + # Complex(3.14159, 0).rationalize(0.00001) # => (355/113) + # Complex(3.14159, 0).rationalize(0.000001) # => (7433/2366) + # Complex(3.14159, 0).rationalize(0.0000001) # => (9208/2931) + # Complex(3.14159, 0).rationalize(0.00000001) # => (47460/15107) + # Complex(3.14159, 0).rationalize(0.000000001) # => (76149/24239) + # Complex(3.14159, 0).rationalize(0.0000000001) # => (314159/100000) + # Complex(3.14159, 0).rationalize(0.0) # => (3537115888337719/1125899906842624) + # + # Related: Complex#to_r. # def rationalize: (?Numeric eps) -> Rational # - # Returns the real part. + # Returns the real value for `self`: # # Complex(7).real #=> 7 # Complex(9, -4).real #=> 9 # + # If `self` was created with [polar + # coordinates](rdoc-ref:Complex@Polar+Coordinates), the returned value is + # computed, and may be inexact: + # + # Complex.polar(1, Math::PI/4).real # => 0.7071067811865476 # Square root of 2. + # def real: () -> Numeric # - # Returns false, even if the complex number has no imaginary part. + # Returns `false`; for compatibility with Numeric#real?. # def real?: () -> false @@ -507,12 +611,21 @@ class Complex < Numeric # - # Returns an array; [cmp.real, cmp.imag]. + # Returns the array `[self.real, self.imag]`: + # + # Complex.rect(1, 2).rect # => [1, 2] + # + # See [Rectangular Coordinates](rdoc-ref:Complex@Rectangular+Coordinates). + # + # If `self` was created with [polar + # coordinates](rdoc-ref:Complex@Polar+Coordinates), the returned value is + # computed, and may be inexact: # - # Complex(1, 2).rectangular #=> [1, 2] + # Complex.polar(1.0, 1.0).rect # => [0.5403023058681398, 0.8414709848078965] + # + # Complex#rectangular is an alias for Complex#rect. # alias rectangular rect @@ -524,38 +637,37 @@ class Complex < Numeric # - # Returns self. - # - # Complex(2).to_c #=> (2+0i) - # Complex(-8, 6).to_c #=> (-8+6i) + # Returns `self`. # def to_c: () -> Complex # - # Returns the value as a float if possible (the imaginary part should be exactly - # zero). + # Returns the value of `self.real` as a Float, if possible: + # + # Complex(1, 0).to_f # => 1.0 + # Complex(1, Rational(0, 1)).to_f # => 1.0 # - # Complex(1, 0).to_f #=> 1.0 - # Complex(1, 0.0).to_f # RangeError - # Complex(1, 2).to_f # RangeError + # Raises RangeError if `self.imag` is not exactly zero (either `Integer(0)` or + # `Rational(0, *n*)`). # def to_f: () -> Float # - # Returns the value as an integer if possible (the imaginary part should be - # exactly zero). + # Returns the value of `self.real` as an Integer, if possible: # - # Complex(1, 0).to_i #=> 1 - # Complex(1, 0.0).to_i # RangeError - # Complex(1, 2).to_i # RangeError + # Complex(1, 0).to_i # => 1 + # Complex(1, Rational(0, 1)).to_i # => 1 + # + # Raises RangeError if `self.imag` is not exactly zero (either `Integer(0)` or + # `Rational(0, *n*)`). # def to_i: () -> Integer @@ -563,30 +675,31 @@ class Complex < Numeric # - # Returns the value as a rational if possible (the imaginary part should be - # exactly zero). + # Returns the value of `self.real` as a Rational, if possible: + # + # Complex(1, 0).to_r # => (1/1) + # Complex(1, Rational(0, 1)).to_r # => (1/1) # - # Complex(1, 0).to_r #=> (1/1) - # Complex(1, 0.0).to_r # RangeError - # Complex(1, 2).to_r # RangeError + # Raises RangeError if `self.imag` is not exactly zero (either `Integer(0)` or + # `Rational(0, *n*)`). # - # See rationalize. + # Related: Complex#rationalize. # def to_r: () -> Rational # - # Returns the value as a string. + # Returns a string representation of `self`: # - # Complex(2).to_s #=> "2+0i" - # Complex('-8/6').to_s #=> "-4/3+0i" - # Complex('1/2i').to_s #=> "0+1/2i" - # Complex(0, Float::INFINITY).to_s #=> "0+Infinity*i" - # Complex(Float::NAN, Float::NAN).to_s #=> "NaN+NaN*i" + # Complex(2).to_s # => "2+0i" + # Complex('-8/6').to_s # => "-4/3+0i" + # Complex('1/2i').to_s # => "0+1/2i" + # Complex(0, Float::INFINITY).to_s # => "0+Infinity*i" + # Complex(Float::NAN, Float::NAN).to_s # => "NaN+NaN*i" # def to_s: () -> String diff --git a/core/dir.rbs b/core/dir.rbs index 446f19688..16c16ff0b 100644 --- a/core/dir.rbs +++ b/core/dir.rbs @@ -221,7 +221,7 @@ class Dir # # * Calls the block with the argument. # * Changes to the given directory. - # * Executes the block + # * Executes the block (yielding the new path). # * Restores the previous working directory. # * Returns the block's return value. # @@ -384,16 +384,14 @@ class Dir # Dir.pwd # => "/var/spool/mail" # dir = Dir.new('/usr') # fd = dir.fileno - # Dir.fchdir(fd) do - # Dir.pwd # => "/usr" - # end - # Dir.pwd # => "/var/spool/mail" + # Dir.fchdir(fd) + # Dir.pwd # => "/usr" # # With a block, temporarily changes the working directory: # # * Calls the block with the argument. # * Changes to the given directory. - # * Executes the block + # * Executes the block (yields no args). # * Restores the previous working directory. # * Returns the block's return value. # @@ -402,7 +400,9 @@ class Dir # # Dir.chdir('/var/spool/mail') # Dir.pwd # => "/var/spool/mail" - # Dir.chdir('/tmp') do + # dir = Dir.new('/tmp') + # fd = dir.fileno + # Dir.fchdir(fd) do # Dir.pwd # => "/tmp" # end # Dir.pwd # => "/var/spool/mail" @@ -763,15 +763,28 @@ class Dir # - # Changes the current working directory to the path of `self`: + # Changes the current working directory to `self`: # # Dir.pwd # => "/" # dir = Dir.new('example') # dir.chdir # Dir.pwd # => "/example" # + # With a block, temporarily changes the working directory: + # + # * Calls the block. + # * Changes to the given directory. + # * Executes the block (yields no args). + # * Restores the previous working directory. + # * Returns the block's return value. + # + # + # Uses Dir.fchdir if available, and Dir.chdir if not, see those methods for + # caveats. + # def chdir: () -> Integer | [T] { () -> T } -> T diff --git a/core/errors.rbs b/core/errors.rbs index 77ec797d4..6c1329cca 100644 --- a/core/errors.rbs +++ b/core/errors.rbs @@ -188,10 +188,6 @@ end # # LoadError: no such file to load -- this/file/does/not/exist # -# -# for RubyGems without Bundler environment. If loading library is not part of -# the default gems and the bundled gems, warn it. -# class LoadError < ScriptError # # the path failed to load @@ -348,7 +344,7 @@ end # # *raises the exception:* # -# NoMethodError: undefined method `to_ary' for "hello":String +# NoMethodError: undefined method `to_ary' for an instance of String # class NoMethodError[T] < NameError[T] # - # Locks or unlocks a file according to *locking_constant* (a logical *or* of the - # values in the table below). Returns `false` if File::LOCK_NB is specified and - # the operation would otherwise have blocked. Not available on all platforms. - # - # Locking constants (in class File): - # - # LOCK_EX | Exclusive lock. Only one process may hold an - # | exclusive lock for a given file at a time. - # ----------+------------------------------------------------ - # LOCK_NB | Don't block when locking. May be combined - # | with other lock options using logical or. - # ----------+------------------------------------------------ - # LOCK_SH | Shared lock. Multiple processes may each hold a - # | shared lock for a given file at the same time. - # ----------+------------------------------------------------ - # LOCK_UN | Unlock. - # - # Example: - # - # # update a counter using write lock - # # don't use "w" because it truncates the file before lock. - # File.open("counter", File::RDWR|File::CREAT, 0644) {|f| - # f.flock(File::LOCK_EX) - # value = f.read.to_i + 1 - # f.rewind - # f.write("#{value}\n") - # f.flush - # f.truncate(f.pos) - # } - # - # # read the counter using read lock - # File.open("counter", "r") {|f| - # f.flock(File::LOCK_SH) - # p f.read - # } + # - flock(locking_constant) -> 0 or false + # --> + # Locks or unlocks a file according to the given `locking_constant`, + # a bitwise OR of the values in the table below. + # Not available on all platforms. + # Returns `false` if `File::LOCK_NB` is specified and the operation would have + # blocked; + # otherwise returns `0`. + # + #
Locking Constants | + #||
---|---|---|
Constant | + #Lock | + #Effect | + #
File::LOCK_EX | + #Exclusive | + #Only one process may hold an exclusive lock for self at a time. | + #
File::LOCK_NB | + #Non-blocking | + #+ # No blocking; may be combined with other File::LOCK_SH or File::LOCK_EX + # using the bitwise OR operator |. + # | + #
File::LOCK_SH | + #Shared | + #Multiple processes may each hold a shared lock for self at the same time. | + #
File::LOCK_UN | + #Unlock | + #Remove an existing lock held by this process. | + #