mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 08:25:20 +08:00
[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 #<Encoding:UTF-8> * Enumerable#inject: typo #=>>
This commit is contained in:
1 parent
536dc6f98b
commit
cfa50b0093
5 files changed
+22
-22
Notes:
git
2026-10-21 08:53:01 +00:00
No files matched your search
@@ -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}, #<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}>]
|
||||
* 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}, #<Set: {6, 7}>]
|
||||
* a.dup.flatten!(-1) # => [0, 1, 2, 3, 4, 5, {foo: 0}, #<Set: {6, 7}>]
|
||||
* 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}, #<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}>]
|
||||
* 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}, #<Set: {6, 7}>]
|
||||
* a.flatten(-1) # => [0, 1, 2, 3, 4, 5, {foo: 0}, #<Set: {6, 7}>]
|
||||
* 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].
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1021,7 +1021,7 @@ ary_inject_op(VALUE ary, VALUE init, VALUE op)
|
||||
* end
|
||||
*
|
||||
* position = "nnneesw".chars.reduce(Turtle.new, :move)
|
||||
* position #=>> #<Turtle:0x00000001052f4698 @y=2, @x=1>
|
||||
* position #=> #<Turtle:0x00000001052f4698 @y=2, @x=1>
|
||||
*
|
||||
* <b>Third Shortcut: Reducer With no Initial Value</b>
|
||||
*
|
||||
|
||||
@@ -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".
|
||||
|
||||
@@ -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 # => <Encoding:UTF-8>
|
||||
* s.encoding # => #<Encoding:UTF-8>
|
||||
* s << 0x00110000 # 1114112 out of char range (RangeError)
|
||||
* s = 'foo'.encode(Encoding::EUC_JP)
|
||||
* s << 0x00800080 # invalid codepoint 0x800080 in EUC-JP (RangeError)
|
||||
|
||||
Reference in new issue
Block a user