From cfa50b00939fd07ae87ffceb730bd2cfbccd8553 Mon Sep 17 00:00:00 2001 From: Shourya Singh Date: Wed, 21 Oct 2026 12:09:46 +0530 Subject: [PATCH] [DOC] Fix outdated results in examples Some example results in the docs no longer match what Ruby prints: * Array#flatten and Array#flatten!: Set#inspect now shows Set[6, 7] * Module: Mod.constants also includes Math::DomainError * Module#const_get and Module#const_set: Floats are shown with full precision * Complex#imag: sin(PI/4) is 0.7071067811865475 * String#<<: missing # in # * Enumerable#inject: typo #=>> --- array.c | 30 +++++++++++++++--------------- complex.c | 2 +- enum.c | 2 +- object.c | 8 ++++---- string.c | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/array.c b/array.c index c44bb78d30e..31f91b1ef37 100644 --- a/array.c +++ b/array.c @@ -6851,16 +6851,16 @@ single_nested_array(VALUE ary) * With non-negative integer argument +depth+, flattens recursively through +depth+ levels: * * a = [ 0, [ 1, [2, 3], 4 ], 5, {foo: 0}, Set.new([6, 7]) ] - * a # => [0, [1, [2, 3], 4], 5, {foo: 0}, #] - * a.dup.flatten!(1) # => [0, 1, [2, 3], 4, 5, {foo: 0}, #] - * a.dup.flatten!(1.1) # => [0, 1, [2, 3], 4, 5, {foo: 0}, #] - * a.dup.flatten!(2) # => [0, 1, 2, 3, 4, 5, {foo: 0}, #] - * a.dup.flatten!(3) # => [0, 1, 2, 3, 4, 5, {foo: 0}, #] + * a # => [0, [1, [2, 3], 4], 5, {foo: 0}, Set[6, 7]] + * a.dup.flatten!(1) # => [0, 1, [2, 3], 4, 5, {foo: 0}, Set[6, 7]] + * a.dup.flatten!(1.1) # => [0, 1, [2, 3], 4, 5, {foo: 0}, Set[6, 7]] + * a.dup.flatten!(2) # => [0, 1, 2, 3, 4, 5, {foo: 0}, Set[6, 7]] + * a.dup.flatten!(3) # => [0, 1, 2, 3, 4, 5, {foo: 0}, Set[6, 7]] * * With +nil+ or negative argument +depth+, flattens all levels: * - * a.dup.flatten! # => [0, 1, 2, 3, 4, 5, {foo: 0}, #] - * a.dup.flatten!(-1) # => [0, 1, 2, 3, 4, 5, {foo: 0}, #] + * a.dup.flatten! # => [0, 1, 2, 3, 4, 5, {foo: 0}, Set[6, 7]] + * a.dup.flatten!(-1) # => [0, 1, 2, 3, 4, 5, {foo: 0}, Set[6, 7]] * * Related: Array#flatten; * see also {Methods for Assigning}[rdoc-ref:Array@Methods+for+Assigning]. @@ -6920,17 +6920,17 @@ rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary) * With non-negative integer argument +depth+, flattens recursively through +depth+ levels: * * a = [ 0, [ 1, [2, 3], 4 ], 5, {foo: 0}, Set.new([6, 7]) ] - * a # => [0, [1, [2, 3], 4], 5, {foo: 0}, #] - * a.flatten(0) # => [0, [1, [2, 3], 4], 5, {foo: 0}, #] - * a.flatten(1 ) # => [0, 1, [2, 3], 4, 5, {foo: 0}, #] - * a.flatten(1.1) # => [0, 1, [2, 3], 4, 5, {foo: 0}, #] - * a.flatten(2) # => [0, 1, 2, 3, 4, 5, {foo: 0}, #] - * a.flatten(3) # => [0, 1, 2, 3, 4, 5, {foo: 0}, #] + * a # => [0, [1, [2, 3], 4], 5, {foo: 0}, Set[6, 7]] + * a.flatten(0) # => [0, [1, [2, 3], 4], 5, {foo: 0}, Set[6, 7]] + * a.flatten(1 ) # => [0, 1, [2, 3], 4, 5, {foo: 0}, Set[6, 7]] + * a.flatten(1.1) # => [0, 1, [2, 3], 4, 5, {foo: 0}, Set[6, 7]] + * a.flatten(2) # => [0, 1, 2, 3, 4, 5, {foo: 0}, Set[6, 7]] + * a.flatten(3) # => [0, 1, 2, 3, 4, 5, {foo: 0}, Set[6, 7]] * * With +nil+ or negative +depth+, flattens all levels. * - * a.flatten # => [0, 1, 2, 3, 4, 5, {foo: 0}, #] - * a.flatten(-1) # => [0, 1, 2, 3, 4, 5, {foo: 0}, #] + * a.flatten # => [0, 1, 2, 3, 4, 5, {foo: 0}, Set[6, 7]] + * a.flatten(-1) # => [0, 1, 2, 3, 4, 5, {foo: 0}, Set[6, 7]] * * Related: Array#flatten!; * see also {Methods for Converting}[rdoc-ref:Array@Methods+for+Converting]. diff --git a/complex.c b/complex.c index af6b33e5ec6..c9e28f9ef74 100644 --- a/complex.c +++ b/complex.c @@ -762,7 +762,7 @@ rb_complex_real(VALUE self) * {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. + * Complex.polar(1, Math::PI/4).imag # => 0.7071067811865475 * */ VALUE diff --git a/enum.c b/enum.c index 492e0c0c1c1..8ca23b6eeea 100644 --- a/enum.c +++ b/enum.c @@ -1021,7 +1021,7 @@ ary_inject_op(VALUE ary, VALUE init, VALUE op) * end * * position = "nnneesw".chars.reduce(Turtle.new, :move) - * position #=>> # + * position #=> # * * Third Shortcut: Reducer With no Initial Value * diff --git a/object.c b/object.c index 0501d4c64fc..3e6bc695df7 100644 --- a/object.c +++ b/object.c @@ -1797,7 +1797,7 @@ rb_obj_cmp(VALUE obj1, VALUE obj2) * end * end * Mod.class #=> Module - * Mod.constants #=> [:CONST, :PI, :E] + * Mod.constants #=> [:CONST, :DomainError, :PI, :E] * Mod.instance_methods #=> [:meth] * */ @@ -2611,7 +2611,7 @@ rb_mod_attr_accessor(int argc, VALUE *argv, VALUE klass) * The value of the constant is returned if a definition is found, * otherwise a +NameError+ is raised. * - * Math.const_get(:PI) #=> 3.14159265358979 + * Math.const_get(:PI) #=> 3.141592653589793 * * This method will recursively look up constant names if a namespaced * class name is provided. For example: @@ -2751,8 +2751,8 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) * Creates a new constant if no constant with the given name previously * existed. * - * Math.const_set("HIGH_SCHOOL_PI", 22.0/7.0) #=> 3.14285714285714 - * Math::HIGH_SCHOOL_PI - Math::PI #=> 0.00126448926734968 + * Math.const_set("HIGH_SCHOOL_PI", 22.0/7.0) #=> 3.142857142857143 + * Math::HIGH_SCHOOL_PI - Math::PI #=> 0.0012644892673496777 * * If +sym+ or +str+ is not a valid constant name a +NameError+ will be * raised with a warning "wrong constant name". diff --git a/string.c b/string.c index 2f987fccdb8..185b452e351 100644 --- a/string.c +++ b/string.c @@ -4149,7 +4149,7 @@ rb_str_append_as_bytes(int argc, VALUE *argv, VALUE str) * Raises RangeError if that codepoint is not representable in the encoding of +self+: * * s = 'foo' - * s.encoding # => + * s.encoding # => # * s << 0x00110000 # 1114112 out of char range (RangeError) * s = 'foo'.encode(Encoding::EUC_JP) * s << 0x00800080 # invalid codepoint 0x800080 in EUC-JP (RangeError)