Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: fix (2021-03) #10505

Merged
merged 6 commits into from Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/hash.cr
Expand Up @@ -1522,7 +1522,6 @@ class Hash(K, V)
# ```
# hash = {"hello" => "world", "foo" => nil}
# hash.compact! # => {"hello" => "world"}
# hash.compact! # => nil
# ```
def compact!
reject! { |key, value| value.nil? }
Expand Down
2 changes: 1 addition & 1 deletion src/http/client.cr
Expand Up @@ -25,7 +25,7 @@
# ```
# require "http/client"
#
# params = URI::Params.encode({"author" => "John Doe", "offset" => "20"}) # => author=John+Doe&offset=20
# params = URI::Params.encode({"author" => "John Doe", "offset" => "20"}) # => "author=John+Doe&offset=20"
# response = HTTP::Client.get URI.new("http", "www.example.com", query: params)
# response.status_code # => 200
# ```
Expand Down
9 changes: 6 additions & 3 deletions src/json/from_json.cr
Expand Up @@ -285,11 +285,14 @@ end
# @[JSON::Field(converter: Enum::ValueConverter(MyEnum))]
# @[YAML::Field(converter: Enum::ValueConverter(MyEnum))]
# property foo : MyEnum = MyEnum::ONE
#
# def initialize(@foo)
# end
# end
#
# foo = Foo.new
# foo.to_json # => %({"my_enum":1})
# foo.to_yaml # => %(---\nmy_enum: 1\n)
# foo = Foo.new(MyEnum::ONE)
# foo.to_json # => %({"foo":1})
# foo.to_yaml # => %(---\nfoo: 1\n)
# ```
#
# NOTE: Automatically assigned enum values are subject to change when the order
Expand Down
10 changes: 5 additions & 5 deletions src/json/pull_parser.cr
Expand Up @@ -230,14 +230,14 @@ class JSON::PullParser
# If the value in unknown, it raises a `ParseException`.
#
# ```
# pull = JSON::PullParser.new %([nil, true, 1, "foo", [1, "two"], {"foo": "bar"}])
# pull = JSON::PullParser.new %([null, true, 1, "foo", [1, "two"], {"foo": "bar"}])
# pull.read_begin_array
# pull.read_raw # => "nil"
# pull.read_raw # => "null"
# pull.read_raw # => "true"
# pull.read_raw # => "1"
# pull.read_raw # => "foo"
# pull.read_raw # => "[1, \"two\"]"
# pull.read_raw # => "{\"foo\": \"bar\"}"
# pull.read_raw # => "\"foo\""
# pull.read_raw # => "[1,\"two\"]"
# pull.read_raw # => "{\"foo\":\"bar\"}"
# pull.read_end_array
# ```
def read_raw
Expand Down
4 changes: 2 additions & 2 deletions src/json/to_json.cr
Expand Up @@ -188,8 +188,8 @@ struct Enum
# end
#
# Sides::LEFT.to_json # => %(["left"])
# (Sides::LEFT | Sides::RIGHT).to_json # => %(["left", "right"])
# Sides::All.to_json # => %(["left", "right"])
# (Sides::LEFT | Sides::RIGHT).to_json # => %(["left","right"])
# Sides::All.to_json # => %(["left","right"])
# Sides::None.to_json # => %([])
# ```
#
Expand Down
8 changes: 4 additions & 4 deletions src/range.cr
Expand Up @@ -213,10 +213,10 @@ struct Range(B, E)
# (1..4).step(by: 2) do |x|
# ary << x
# end
# ary # => [1, 3]
# (1..4).step(by: 2).to_a # => [1, 3]
# (1..4).step(by: 1).to_a # => [1, 2, 3, 4]
# (1..4).step(by: 1, exclusive: true).to_a # => [1, 2, 3]
# ary # => [1, 3]
# (1..4).step(by: 2).to_a # => [1, 3]
# (1..4).step(by: 1).to_a # => [1, 2, 3, 4]
# (1...4).step(by: 1).to_a # => [1, 2, 3]
# ```
#
# The implementation is based on `B#step` method if available. The interface
Expand Down
4 changes: 2 additions & 2 deletions src/string.cr
Expand Up @@ -4108,7 +4108,7 @@ class String
#
# ```
# io = IO::Memory.new
# "Purple".rjust(8, '-', io)
# "Purple".rjust(io, 8, '-')
# io.to_s # => "--Purple"
# ```
def rjust(io : IO, len : Int, char : Char = ' ') : Nil
Expand All @@ -4133,7 +4133,7 @@ class String
#
# ```
# io = IO::Memory.new
# "Purple".center(9, '-', io)
# "Purple".center(io, 9, '-')
# io.to_s # => "-Purple--"
# ```
def center(io : IO, len : Int, char : Char = ' ') : Nil
Expand Down
4 changes: 2 additions & 2 deletions src/uri.cr
Expand Up @@ -282,9 +282,9 @@ class URI
#
# ```
# uri = URI.parse "http://user:pass@example.com:80/path?query"
# uri.authority # => "user:pass@example.com"
# uri.authority # => "user:pass@example.com:80"
#
# uri = URI.parse(path: "/relative")
# uri = URI.parse("/relative")
# uri.authority # => nil
# ```
def authority : String?
Expand Down
29 changes: 9 additions & 20 deletions src/yaml/to_yaml.cr
Expand Up @@ -149,9 +149,9 @@ struct Enum
# RIGHT
# end
#
# Sides::LEFT.to_yaml # => %(--- ["left"]\n)
# (Sides::LEFT | Sides::RIGHT).to_yaml # => %(--- ["left", "right"]\n)
# Sides::All.to_yaml # => %(--- ["left", "right"]\n)
# Sides::LEFT.to_yaml # => %(--- [left]\n)
# (Sides::LEFT | Sides::RIGHT).to_yaml # => %(--- [left, right]\n)
# Sides::All.to_yaml # => %(--- [left, right]\n)
# Sides::None.to_yaml # => %(--- []\n)
# ```
#
Expand Down Expand Up @@ -193,24 +193,13 @@ module Enum::ValueConverter(T)
# used for serialization.
#
# ```
# enum Stages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i just noticed that here there are also some definitions that should stay in order to make them self-contained.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed to revert the yaml one. 馃槂

# INITIAL
# SECOND_STAGE
# end
#
# Enum::ValueConverter.to_yaml(Stages::INITIAL) # => %(0)
# Enum::ValueConverter.to_yaml(Stages::SECOND_STAGE) # => %(1)
#
# @[Flags]
# enum Sides
# LEFT
# RIGHT
# end
# Enum::ValueConverter.to_yaml(Stages::INITIAL) # => %(--- 0\n)
# Enum::ValueConverter.to_yaml(Stages::SECOND_STAGE) # => %(--- 1\n)
#
# Enum::ValueConverter.to_yaml(Sides::LEFT) # => %(1)
# Enum::ValueConverter.to_yaml(Sides::LEFT | Sides::RIGHT) # => %(3)
# Enum::ValueConverter.to_yaml(Sides::All) # => %(3)
# Enum::ValueConverter.to_yaml(Sides::None) # => %(0)
# Enum::ValueConverter.to_yaml(Sides::LEFT) # => %(--- 1\n)
# Enum::ValueConverter.to_yaml(Sides::LEFT | Sides::RIGHT) # => %(--- 3\n)
# Enum::ValueConverter.to_yaml(Sides::All) # => %(--- 3\n)
# Enum::ValueConverter.to_yaml(Sides::None) # => %(--- 0\n)
# ```
#
# `Enum#to_yaml` offers a different serialization strategy based on the member
Expand Down