[前][次][番号順一覧][スレッド一覧]

ruby-changes:68536

From: Burdette <ko1@a...>
Date: Wed, 20 Oct 2021 02:00:36 +0900 (JST)
Subject: [ruby-changes:68536] 3e96b94eba (master): Enhanced RDoc for Numeric (#4991)

https://git.ruby-lang.org/ruby.git/commit/?id=3e96b94eba

From 3e96b94eba0d5374fe69a7c87b9bc0dc060ecf9c Mon Sep 17 00:00:00 2001
From: Burdette Lamar <BurdetteLamar@Y...>
Date: Tue, 19 Oct 2021 12:00:22 -0500
Subject: Enhanced RDoc for Numeric (#4991)

Treated:

    #@-
    #fdiv
    #div
    #abs
    #zero?
    #nonzero?
    #to_int
    #positive?
    #negative?
---
 numeric.c | 92 ++++++++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 59 insertions(+), 33 deletions(-)

diff --git a/numeric.c b/numeric.c
index db2b2eb279..d216240520 100644
--- a/numeric.c
+++ b/numeric.c
@@ -566,7 +566,7 @@ num_dup(VALUE x) https://github.com/ruby/ruby/blob/trunk/numeric.c#L566
 
 /*
  *  call-seq:
- *    +num -> self
+ *    +self -> self
  *
  *  Returns +self+.
  *
@@ -588,7 +588,7 @@ num_uplus(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L588
  *    -2.i             # => (0-2i)
  *    2.0.i            # => (0+2.0i)
  *    Rational(1, 2).i # => (0+(1/2)*i)
- *    Complex(3, 4).i # Raises NoMethodError.
+ *    Complex(3, 4).i  # Raises NoMethodError.
  *
  */
 
@@ -600,7 +600,7 @@ num_imaginary(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L600
 
 /*
  *  call-seq:
- *     -num  ->  numeric
+ *    -self -> numeric
  *
  *  Unary Minus---Returns the receiver, negated.
  */
@@ -618,9 +618,15 @@ num_uminus(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L618
 
 /*
  *  call-seq:
- *     num.fdiv(numeric)  ->  float
+ *    fdiv(other) -> float
+ *
+ *  Returns the quotient <tt>self/other</tt> as a float,
+ *  using method +/+ in the derived class of +self+.
+ *  (\Numeric itself does not define method +/+.)
+ *
+ *  Of the Core and Standard Library classes,
+ *  only BigDecimal uses this implementation.
  *
- *  Returns float division.
  */
 
 static VALUE
@@ -631,14 +637,15 @@ num_fdiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L637
 
 /*
  *  call-seq:
- *     num.div(numeric)  ->  integer
+ *    div(other) -> integer
  *
- *  Uses +/+ to perform division, then converts the result to an integer.
- *  Numeric does not define the +/+ operator; this is left to subclasses.
+ *  Returns the quotient <tt>self/other</tt> as an integer (via +floor+),
+ *  using method +/+ in the derived class of +self+.
+ *  (\Numeric itself does not define method +/+.)
  *
- *  Equivalent to <code>num.divmod(numeric)[0]</code>.
+ *  Of the Core and Standard Library classes,
+ *  Float, Rational, and Complex use this implementation.
  *
- *  See Numeric#divmod.
  */
 
 static VALUE
@@ -779,16 +786,16 @@ num_divmod(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L786
 
 /*
  *  call-seq:
- *     num.abs        ->  numeric
- *     num.magnitude  ->  numeric
+ *    abs -> numeric
  *
- *  Returns the absolute value of +num+.
+ *  Returns the absolute value of +self+.
  *
- *     12.abs         #=> 12
- *     (-34.56).abs   #=> 34.56
- *     -34.56.abs     #=> 34.56
+ *    12.abs        #=> 12
+ *    (-34.56).abs  #=> 34.56
+ *    -34.56.abs    #=> 34.56
  *
  *  Numeric#magnitude is an alias for Numeric#abs.
+ *
  */
 
 static VALUE
@@ -802,9 +809,13 @@ num_abs(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L809
 
 /*
  *  call-seq:
- *     num.zero?  ->  true or false
+ *    zero? -> true or false
+ *
+ *  Returns +true+ if +zero+ has a zero value, +false+ otherwise.
+ *
+ *  Of the Core and Standard Library classes,
+ *  only Rational and Complex use this implementation.
  *
- *  Returns +true+ if +num+ has a zero value.
  */
 
 static VALUE
@@ -831,15 +842,20 @@ rb_int_zero_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L842
 
 /*
  *  call-seq:
- *     num.nonzero?  ->  self or nil
+ *    nonzero?  ->  self or nil
+ *
+ *  Returns +self+ if +self+ is not a zero value, +nil+ otherwise;
+ *  uses method <tt>zero?</tt> for the evaluation.
  *
- *  Returns +self+ if +num+ is not zero, +nil+ otherwise.
+ *  The returned +self+ allows the method to be chained:
  *
- *  This behavior is useful when chaining comparisons:
+ *    a = %w[z Bb bB bb BB a aA Aa AA A]
+ *    a.sort {|a, b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
+ *    # => ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
+ *
+ *  Of the Core and Standard Library classes,
+ *  Integer, Float, Rational, and Complex use this implementation.
  *
- *     a = %w( z Bb bB bb BB a aA Aa AA A )
- *     b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
- *     b   #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
  */
 
 static VALUE
@@ -853,13 +869,21 @@ num_nonzero_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L869
 
 /*
  *  call-seq:
- *     num.to_int  ->  integer
+ *    to_int -> integer
  *
- *  Invokes the child class's +to_i+ method to convert +num+ to an integer.
+ *  Returns +self+ as an integer;
+ *  converts using method +to_i+ in the derived class.
+ *
+ *  Of the Core and Standard Library classes,
+ *  only Rational and Complex use this implementation.
+ *
+ *  Examples:
+ *
+ *    Rational(1, 2).to_int # => 0
+ *    Rational(2, 1).to_int # => 2
+ *    Complex(2, 0).to_int  # => 2
+ *    Complex(2, 1)         # Raises RangeError (non-zero imaginary part)
  *
- *      1.0.class          #=> Float
- *      1.0.to_int.class   #=> Integer
- *      1.0.to_i.class     #=> Integer
  */
 
 static VALUE
@@ -870,9 +894,10 @@ num_to_int(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L894
 
 /*
  *  call-seq:
- *     num.positive?  ->  true or false
+ *    positive? -> true or false
+ *
+ *  Returns +true+ if +self+ is greater than 0, +false+ otherwise.
  *
- *  Returns +true+ if +num+ is greater than 0.
  */
 
 static VALUE
@@ -893,9 +918,10 @@ num_positive_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L918
 
 /*
  *  call-seq:
- *     num.negative?  ->  true or false
+ *    negative? -> true or false
+ *
+ *  Returns +true+ if +self+ is less than 0, +false+ otherwise.
  *
- *  Returns +true+ if +num+ is less than 0.
  */
 
 static VALUE
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]