diff --git a/src/big/big_decimal.cr b/src/big/big_decimal.cr index aaa35a374092..8450ce2c7317 100644 --- a/src/big/big_decimal.cr +++ b/src/big/big_decimal.cr @@ -199,8 +199,8 @@ struct BigDecimal < Number # defines a maximum number of iterations in case the division is not exact. # # ``` - # BigDecimal(1).div(BigDecimal(2)) # => BigDecimal(@value=5, @scale=2) - # BigDecimal(1).div(BigDecimal(3), 5) # => BigDecimal(@value=33333, @scale=5) + # BigDecimal.new(1).div(BigDecimal.new(2)) # => BigDecimal(@value=5, @scale=2) + # BigDecimal.new(1).div(BigDecimal.new(3), 5) # => BigDecimal(@value=33333, @scale=5) # ``` def div(other : BigDecimal, max_div_iterations = DEFAULT_MAX_DIV_ITERATIONS) : BigDecimal check_division_by_zero other @@ -531,7 +531,7 @@ struct Int # Converts `self` to `BigDecimal`. # ``` # require "big" - # 1212341515125412412412421.to_big_d + # 12123415151254124124.to_big_d # ``` def to_big_d BigDecimal.new(self) diff --git a/src/big/big_int.cr b/src/big/big_int.cr index d3430bdf2d54..e880399ac106 100644 --- a/src/big/big_int.cr +++ b/src/big/big_int.cr @@ -27,7 +27,7 @@ struct BigInt < Int # # ``` # BigInt.new("123456789123456789123456789123456789") # => 123456789123456789123456789123456789 - # BigInt.new("123_456_789_123_456_789_123_456_789") # => 123456789012345678901234567890 + # BigInt.new("123_456_789_123_456_789_123_456_789") # => 123456789123456789123456789 # BigInt.new("1234567890ABCDEF", base: 16) # => 1311768467294899695 # ``` def initialize(str : String, base = 10) diff --git a/src/enumerable.cr b/src/enumerable.cr index bf8064049060..592beea46044 100644 --- a/src/enumerable.cr +++ b/src/enumerable.cr @@ -1124,7 +1124,7 @@ module Enumerable(T) # `pattern === element` is false. # # ``` - # [1, 3, 2, 5, 4, 6].reject(3..5).should eq([1, 2, 6]) + # [1, 3, 2, 5, 4, 6].reject(3..5) # => [1, 2, 6] # ``` def reject(pattern) reject { |e| pattern === e } @@ -1160,7 +1160,7 @@ module Enumerable(T) # `pattern === element`. # # ``` - # [1, 3, 2, 5, 4, 6].select(3..5).should eq([3, 5, 4]) + # [1, 3, 2, 5, 4, 6].select(3..5) # => [3, 5, 4] # ``` def select(pattern) self.select { |e| pattern === e } diff --git a/src/hash.cr b/src/hash.cr index 8e268004fabf..269e8bb873c6 100644 --- a/src/hash.cr +++ b/src/hash.cr @@ -688,7 +688,7 @@ class Hash(K, V) # # ``` # hash = {:a => 1, :b => 2, :c => 3} - # hash.transform_keys { |key| key.to_s } # => {"A" => 1, "B" => 2, "C" => 3} + # hash.transform_keys { |key| key.to_s } # => {"a" => 1, "b" => 2, "c" => 3} # ``` def transform_keys(&block : K -> K2) forall K2 each_with_object({} of K2 => V) do |(key, value), memo| @@ -702,6 +702,7 @@ class Hash(K, V) # ``` # hash = {:a => 1, :b => 2, :c => 3} # hash.transform_values { |value| value + 1 } # => {:a => 2, :b => 3, :c => 4} + # ``` def transform_values(&block : V -> V2) forall V2 each_with_object({} of K => V2) do |(key, value), memo| memo[key] = yield(value) @@ -715,6 +716,7 @@ class Hash(K, V) # hash = {:a => 1, :b => 2, :c => 3} # hash.transform_values! { |value| value + 1 } # hash # => {:a => 2, :b => 3, :c => 4} + # ``` def transform_values!(&block : V -> V) current = @first while current diff --git a/src/http/params.cr b/src/http/params.cr index fc1649313daf..2f5535dda73d 100644 --- a/src/http/params.cr +++ b/src/http/params.cr @@ -172,8 +172,8 @@ module HTTP # Returns `true` if params is empty. # # ``` - # Params.new.empty? # => true - # Params.parse("foo=bar&foo=baz&qux=zoo").empty? # => false + # HTTP::Params.new.empty? # => true + # HTTP::Params.parse("foo=bar&foo=baz&qux=zoo").empty? # => false # ``` delegate empty?, to: raw_params diff --git a/src/http/server.cr b/src/http/server.cr index f77a89c98782..30fcfbfc9514 100644 --- a/src/http/server.cr +++ b/src/http/server.cr @@ -296,9 +296,9 @@ class HTTP::Server # # ``` # server = HTTP::Server.new { } - # server.bind("tcp://localhost:80") # => Socket::IPAddress.new("127.0.0.1", 8080) - # server.bind("unix:///tmp/server.sock") # => Socket::UNIXAddress.new("/tmp/server.sock") - # server.bind("tls://127.0.0.1:443?key=private.key&cert=certificate.cert&ca=ca.crt) # => Socket::IPAddress.new("127.0.0.1", 443) + # server.bind("tcp://localhost:80") # => Socket::IPAddress.new("127.0.0.1", 8080) + # server.bind("unix:///tmp/server.sock") # => Socket::UNIXAddress.new("/tmp/server.sock") + # server.bind("tls://127.0.0.1:443?key=private.key&cert=certificate.cert&ca=ca.crt") # => Socket::IPAddress.new("127.0.0.1", 443) # ``` def bind(uri : String) : Socket::Address bind(URI.parse(uri)) diff --git a/src/humanize.cr b/src/humanize.cr index 34464eb562b9..ea4f85a2b73b 100644 --- a/src/humanize.cr +++ b/src/humanize.cr @@ -98,7 +98,7 @@ struct Number # # ``` # 1_200_000_000.humanize # => "1.2G" - # 0.000_000_012.humanize # => "12n" + # 0.000_000_012.humanize # => "12.0n" # ``` # # If *significant* is `false`, the number of *precision* digits is preserved @@ -139,7 +139,7 @@ struct Number # # ``` # 1_200_000_000.humanize # => "1.2G" - # 0.000_000_012.humanize # => "12n" + # 0.000_000_012.humanize # => "12.0n" # ``` # # If *significant* is `false`, the number of *precision* digits is preserved @@ -172,7 +172,7 @@ struct Number # end # # humanize_length(1_420) # => "1.42 km" - # humanize_length(0.23) # => "23 cm" + # humanize_length(0.23) # => "23.0 cm" # ``` # # See `Int#humanize_bytes` to format a file size. @@ -275,9 +275,9 @@ struct Int # # ``` # 1.humanize_bytes # => "1B" - # 1024.humanize_bytes # => "1.0KB" - # 1536.humanize_bytes # => "1.5KB" - # 524288.humanize_bytes # => "512KB" + # 1024.humanize_bytes # => "1.0kiB" + # 1536.humanize_bytes # => "1.5kiB" + # 524288.humanize_bytes # => "512kiB" # 1073741824.humanize_bytes(format: :IEC) # => "1.0GiB" # ``` # diff --git a/src/iterator.cr b/src/iterator.cr index 5f7bf0d60620..c7a872078a8d 100644 --- a/src/iterator.cr +++ b/src/iterator.cr @@ -177,7 +177,7 @@ module Iterator(T) # iterators to chain is large (usually greater than 4) or undetermined. # # ``` - # array_of_iters = [[1], [2, 3], [4, 5, 6]] + # array_of_iters = [[1], [2, 3], [4, 5, 6]].each.map &.each # iter = Iterator(Int32).chain array_of_iters # iter.next # => 1 # iter.next # => 2 @@ -728,7 +728,7 @@ module Iterator(T) # where `pattern === element` does not hold. # # ``` - # iter = [2, 3, 1, 5, 4, 6].reject(3..5) + # iter = [2, 3, 1, 5, 4, 6].each.reject(3..5) # iter.next # => 2 # iter.next # => 1 # iter.next # => 6 @@ -785,7 +785,7 @@ module Iterator(T) # where `pattern === element`. # # ``` - # iter = [1, 3, 2, 5, 4, 6].select(3..5) + # iter = [1, 3, 2, 5, 4, 6].each.select(3..5) # iter.next # => 3 # iter.next # => 5 # iter.next # => 4 @@ -1310,7 +1310,7 @@ module Iterator(T) # iter.next # => ['d', 'E'] # iter.next # => ['F'] # iter.next # => ['g', 'h'] - # iter.next # => Iterator::Stop + # iter.next # => Iterator::Stop::INSTANCE # ``` # # By default, a new array is created and yielded for each slice when invoking `next`. @@ -1338,7 +1338,7 @@ module Iterator(T) # iter.next # => ['d', 'E'] # iter.next # => ['F'] # iter.next # => ['g', 'h'] - # iter.next # => Iterator::Stop + # iter.next # => Iterator::Stop::INSTANCE # ``` # # By default, a new array is created and yielded for each slice when invoking `next`. @@ -1416,7 +1416,7 @@ module Iterator(T) # iter.next # => ['C', 'd'] # iter.next # => ['E'] # iter.next # => ['F', 'g', 'h'] - # iter.next # => Iterator::Stop + # iter.next # => Iterator::Stop::INSTANCE # ``` # # By default, a new array is created and yielded for each slice when invoking `next`. @@ -1444,7 +1444,7 @@ module Iterator(T) # iter.next # => ['C', 'd'] # iter.next # => ['E'] # iter.next # => ['F', 'g', 'h'] - # iter.next # => Iterator::Stop + # iter.next # => Iterator::Stop::INSTANCE # ``` # # By default, a new array is created and yielded for each slice when invoking `next`. @@ -1528,7 +1528,7 @@ module Iterator(T) # iter.next # => [9, 10, 11, 12] # iter.next # => [15, 16] # iter.next # => [19, 20, 21] - # iter.next # => Iterator::Stop + # iter.next # => Iterator::Stop::INSTANCE # ``` # # By default, a new array is created and yielded for each slice when invoking `next`. @@ -1558,7 +1558,7 @@ module Iterator(T) # iter.next # => [9, 10, 11, 12] # iter.next # => [15, 16] # iter.next # => [19, 20, 21] - # iter.next # => Iterator::Stop + # iter.next # => Iterator::Stop::INSTANCE # ``` # # By default, a new array is created and yielded for each slice when invoking `next`. diff --git a/src/kernel.cr b/src/kernel.cr index 6c50ca73491c..81a47527ed4a 100644 --- a/src/kernel.cr +++ b/src/kernel.cr @@ -276,8 +276,8 @@ end # sprintf "%20.8g", 1234.56789 # => " 1234.5679" # sprintf "%20.8g", 123456789 # => " 1.2345679e+08" # sprintf "%20.8G", 123456789 # => " 1.2345679E+08" -# sprintf "%20.8g", -123456789 # => " -1.2345679e+08" -# sprintf "%20.8G", -123456789 # => " -1.2345679E+08" +# sprintf "%20.8g", -123456789 # => " -1.2345679e+08" +# sprintf "%20.8G", -123456789 # => " -1.2345679E+08" # ``` # # The field width is an optional integer, followed optionally by a @@ -289,7 +289,7 @@ end # sprintf "%20d", 123 # => " 123" # sprintf "%+20d", 123 # => " +123" # sprintf "%020d", 123 # => "00000000000000000123" -# sprintf "%+020d", 12 # => "+0000000000000000123" +# sprintf "%+020d", 123 # => "+0000000000000000123" # sprintf "% 020d", 123 # => " 0000000000000000123" # sprintf "%-20d", 123 # => "123 " # sprintf "%-+20d", 123 # => "+123 " @@ -315,7 +315,7 @@ end # sprintf "%020.8o", 123 # => "00000000000000000173" # sprintf "%20.8x", 123 # => " 7b" # sprintf "%020.8x", 123 # => "0000000000000000007b" -# sprintf "%20.8b", 123 # => " 01111011" +# sprintf "%20.8b", 123 # => " 1111011" # sprintf "%20.8d", -123 # => " -123" # sprintf "%020.8d", -123 # => "0000000000000000-123" # sprintf "%20.8o", -123 # => " -173" diff --git a/src/mime.cr b/src/mime.cr index 40e73a25effe..bb033dc72a43 100644 --- a/src/mime.cr +++ b/src/mime.cr @@ -5,8 +5,8 @@ require "crystal/system/mime" # ``` # require "mime" # -# MIME.from_extension(".html") # => "text/html; charset=utf-8" -# MIME.from_filename("path/file.html") # => "text/html; charset=utf-8" +# MIME.from_extension(".html") # => "text/html" +# MIME.from_filename("path/file.html") # => "text/html" # ``` # # The registry will be populated with some default values (see `DEFAULT_TYPES`) diff --git a/src/mime/multipart/builder.cr b/src/mime/multipart/builder.cr index 006f6e66b138..77d7e9461462 100644 --- a/src/mime/multipart/builder.cr +++ b/src/mime/multipart/builder.cr @@ -27,7 +27,7 @@ module MIME::Multipart # ``` # io = IO::Memory.new # This is a stub. Actually, any IO can be used. # builder = MIME::Multipart::Builder.new(io, "a4VF") - # builder.content_type("mixed") # => "multipart/mixed; boundary=\"a4VF\"" + # builder.content_type("mixed") # => "multipart/mixed; boundary=a4VF" # ``` def content_type(subtype = "mixed") MIME::MediaType.new("multipart/#{subtype}", {"boundary" => @boundary}).to_s diff --git a/src/static_array.cr b/src/static_array.cr index dedd62950fb9..650a519a6b78 100644 --- a/src/static_array.cr +++ b/src/static_array.cr @@ -19,7 +19,7 @@ # ints = uninitialized Int32[3] # ints[0] = 0 # ints[1] = 8 -# ints[3] = 15 +# ints[2] = 15 # ``` # # For number types there is also `Number.static_array` which can be used to initialize diff --git a/src/tuple.cr b/src/tuple.cr index 33eefe457443..b973c8c142aa 100644 --- a/src/tuple.cr +++ b/src/tuple.cr @@ -84,8 +84,8 @@ struct Tuple # Creates a tuple from the given array, with elements casted to the given types. # # ``` - # Tuple(String, Int64).from(["world", 2]) # => {"world", 2} - # Tuple(String, Int64).from(["world", 2]).class # => {String, Int64} + # Tuple(String, Int64).from(["world", 2_i64]) # => {"world", 2_i64} + # Tuple(String, Int64).from(["world", 2_i64]).class # => {String, Int64} # ``` # # See also: `#from`. @@ -101,11 +101,13 @@ struct Tuple # This allows you to easily pass an array as individual arguments to a method. # # ``` + # require "json" + # # def speak_about(thing : String, n : Int64) # "I see #{n} #{thing}s" # end # - # data = JSON.parse(%(["world", 2])).as_a + # data = JSON.parse(%(["world", 2])).as_a.map(&.raw) # speak_about(*{String, Int64}.from(data)) # => "I see 2 worlds" # ``` def from(array : Array) diff --git a/src/uuid/json.cr b/src/uuid/json.cr index 80d868913503..bd4cbe4a8d7e 100644 --- a/src/uuid/json.cr +++ b/src/uuid/json.cr @@ -17,7 +17,7 @@ require "uuid" # example = Example.from_json(%({"id": "ba714f86-cac6-42c7-8956-bcf5105e1b81"})) # # uuid = UUID.new("87b3042b-9b9a-41b7-8b15-a93d3f17025e") -# uuid.to_json # => "87b3042b-9b9a-41b7-8b15-a93d3f17025e" +# uuid.to_json # => "\"87b3042b-9b9a-41b7-8b15-a93d3f17025e\"" # ``` struct UUID def self.new(pull : JSON::PullParser)