Skip to content

Commit

Permalink
Add missing require statements for the API (A-N)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maroo-b committed Mar 20, 2019
1 parent 076b518 commit 29cb212
Show file tree
Hide file tree
Showing 31 changed files with 324 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/benchmark.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ require "./benchmark/**"
# calculation time. This can be configured:
#
# ```
# require "benchmark"
#
# Benchmark.ips(warmup: 4, calculation: 10) do |x|
# x.report("sleep") { sleep 0.01 }
# end
Expand Down
5 changes: 5 additions & 0 deletions src/big/big_int.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct BigInt < Int
# Raises `ArgumentError` if the string doesn't denote a valid integer.
#
# ```
# require "big"
#
# BigInt.new("123456789123456789123456789123456789") # => 123456789123456789123456789123456789
# BigInt.new("123_456_789_123_456_789_123_456_789") # => 123456789012345678901234567890
# BigInt.new("1234567890ABCDEF", base: 16) # => 1311768467294899695
Expand Down Expand Up @@ -350,6 +352,7 @@ struct BigInt < Int
# Returns a string representation of self.
#
# ```
# require "big"
# BigInt.new("123456789101101987654321").to_s # => 123456789101101987654321
# ```
def to_s : String
Expand All @@ -365,6 +368,8 @@ struct BigInt < Int
# Returns a string containing the representation of big radix base (2 through 36).
#
# ```
# require "big"
#
# BigInt.new("123456789101101987654321").to_s(8) # => "32111154373025463465765261"
# BigInt.new("123456789101101987654321").to_s(16) # => "1a249b1f61599cd7eab1"
# BigInt.new("123456789101101987654321").to_s(36) # => "k3qmt029k48nmpd"
Expand Down
4 changes: 4 additions & 0 deletions src/big/big_rational.cr
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct BigRational < Number
# Divides the rational by (2 ** *other*)
#
# ```
# require "big"
# BigRational.new(2, 3) >> 2 # => 1/6
# ```
def >>(other : Int)
Expand All @@ -139,6 +140,7 @@ struct BigRational < Number
# Multiplies the rational by (2 ** *other*)
#
# ```
# require "big"
# BigRational.new(2, 3) << 2 # => 8/3
# ```
def <<(other : Int)
Expand Down Expand Up @@ -198,6 +200,8 @@ struct BigRational < Number
# Optionally takes a radix base (2 through 36).
#
# ```
# require "big"
#
# r = BigRational.new(8243243, 562828882)
# r.to_s # => "8243243/562828882"
# r.to_s(16) # => "7dc82b/218c1652"
Expand Down
12 changes: 12 additions & 0 deletions src/bit_array.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct BitArray
# Raises `IndexError` if trying to access a bit outside the array's range.
#
# ```
# require "bit_array"
#
# ba = BitArray.new(5)
# ba[3] = true
# ```
Expand All @@ -75,6 +77,8 @@ struct BitArray
# Raises `IndexError` if the starting index is out of range.
#
# ```
# require "bit_array"
#
# ba = BitArray.new(5)
# ba[0] = true; ba[2] = true; ba[4] = true
# ba # => BitArray[10101]
Expand All @@ -99,6 +103,8 @@ struct BitArray
# Raises `IndexError` if the starting index is out of range.
#
# ```
# require "bit_array"
#
# ba = BitArray.new(5)
# ba[0] = true; ba[2] = true; ba[4] = true
# ba # => BitArray[10101]
Expand Down Expand Up @@ -175,6 +181,8 @@ struct BitArray
# Raises `IndexError` if trying to access a bit outside the array's range.
#
# ```
# require "bit_array"
#
# ba = BitArray.new(5)
# ba[3] # => false
# ba.toggle(3)
Expand All @@ -188,6 +196,8 @@ struct BitArray
# Inverts all bits in the array. Falses become `true` and vice versa.
#
# ```
# require "bit_array"
#
# ba = BitArray.new(5)
# ba[2] = true; ba[3] = true
# ba # => BitArray[00110]
Expand All @@ -203,6 +213,8 @@ struct BitArray
# Creates a string representation of self.
#
# ```
# require "bit_array"
#
# ba = BitArray.new(5)
# ba.to_s # => "BitArray[00000]"
# ```
Expand Down
18 changes: 18 additions & 0 deletions src/colorize.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,65 @@
#
# There are alternative ways to change the foreground color:
# ```
# require "colorize"
#
# "foo".colorize.fore(:green)
# "foo".colorize.green
# ```
#
# To change the background color, the following methods are available:
# ```
# require "colorize"
#
# "foo".colorize.back(:green)
# "foo".colorize.on(:green)
# "foo".colorize.on_green
# ```
#
# You can also pass an RGB color to `colorize`:
# ```
# require "colorize"
#
# "foo".colorize(Colorize::ColorRGB.new(0, 255, 255)) # => "foo" in aqua
# ```
#
# Or an 8-bit color:
# ```
# require "colorize"
#
# "foo".colorize(Colorize::Color256.new(208)) # => "foo" in orange
# ```
#
# It's also possible to change the text decoration:
# ```
# require "colorize"
#
# "foo".colorize.mode(:underline)
# "foo".colorize.underline
# ```
#
# The `colorize` method returns a `Colorize::Object` instance,
# which allows chaining methods together:
# ```
# require "colorize"
#
# "foo".colorize.fore(:yellow).back(:blue).mode(:underline)
# ```
#
# With the `toggle` method you can temporarily disable adding the escape codes.
# Settings of the instance are preserved however and can be turned back on later:
# ```
# require "colorize"
#
# "foo".colorize(:red).toggle(false) # => "foo" without color
# "foo".colorize(:red).toggle(false).toggle(true) # => "foo" in red
# ```
#
# The color `:default` will just leave the object as it is (but it's an `Colorize::Object(String)` then).
# That's handy in for example conditions:
# ```
# require "colorize"
#
# "foo".colorize(some_bool ? :green : :default)
# ```
#
Expand Down Expand Up @@ -98,6 +114,8 @@ module Colorize
# The default value is `true`.
#
# ```
# require "colorize"
#
# Colorize.enabled = true
# "hello".colorize.red.to_s # => "\e[31mhello\e[0m"
#
Expand Down
14 changes: 14 additions & 0 deletions src/complex.cr
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ struct Complex
# Writes this complex object to an *io*.
#
# ```
# require "complex"
#
# Complex.new(42, 2).to_s # => "42.0 + 2.0i"
# ```
def to_s(io : IO) : Nil
Expand All @@ -96,6 +98,8 @@ struct Complex
# Writes this complex object to an *io*, surrounded by parentheses.
#
# ```
# require "complex"
#
# Complex.new(42, 2).inspect # => "(42.0 + 2.0i)"
# ```
def inspect(io : IO) : Nil
Expand All @@ -108,6 +112,8 @@ struct Complex
# number form, using the Pythagorean theorem.
#
# ```
# require "complex"
#
# Complex.new(42, 2).abs # => 42.04759208325728
# Complex.new(-42, 2).abs # => 42.04759208325728
# ```
Expand All @@ -118,6 +124,8 @@ struct Complex
# Returns the square of absolute value in a number form.
#
# ```
# require "complex"
#
# Complex.new(42, 2).abs2 # => 1768
# ```
def abs2
Expand All @@ -136,6 +144,8 @@ struct Complex
# Returns a `Tuple` with the `abs` value and the `phase`.
#
# ```
# require "complex"
#
# Complex.new(42, 2).polar # => {42.047592083257278, 0.047583103276983396}
# ```
def polar
Expand All @@ -145,6 +155,8 @@ struct Complex
# Returns the conjugate of `self`.
#
# ```
# require "complex"
#
# Complex.new(42, 2).conj # => 42.0 - 2.0i
# Complex.new(42, -2).conj # => 42.0 + 2.0i
# ```
Expand Down Expand Up @@ -181,6 +193,8 @@ struct Complex
# Calculates the exp of `self`.
#
# ```
# require "complex"
#
# Complex.new(4, 2).exp # => -22.720847417619233 + 49.645957334580565i
# ```
def exp
Expand Down
6 changes: 6 additions & 0 deletions src/crypto/bcrypt/password.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Crypto::Bcrypt::Password
# Hashes a password.
#
# ```
# require "crypto/bcrypt/password"
#
# password = Crypto::Bcrypt::Password.create("super secret", cost: 10)
# # => $2a$10$rI4xRiuAN2fyiKwynO6PPuorfuoM4L2PVv6hlnVJEmNLjqcibAfHq
# ```
Expand All @@ -33,6 +35,8 @@ class Crypto::Bcrypt::Password
# Loads a bcrypt hash.
#
# ```
# require "crypto/bcrypt/password"
#
# password = Crypto::Bcrypt::Password.new("$2a$10$X6rw/jDiLBuzHV./JjBNXe8/Po4wTL0fhdDNdAdjcKN/Fup8tGCya")
# password.version # => "2a"
# password.salt # => "X6rw/jDiLBuzHV./JjBNXe"
Expand All @@ -54,6 +58,8 @@ class Crypto::Bcrypt::Password
# Verifies a password against the hash.
#
# ```
# require "crypto/bcrypt/password"
#
# password = Crypto::Bcrypt::Password.create("super secret")
# password == "wrong secret" # => false
# password == "super secret" # => true
Expand Down
10 changes: 10 additions & 0 deletions src/csv.cr
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class CSV
# non-standard csv cell separators and quote characters.
#
# ```
# require "csv"
#
# CSV.parse("one,two\nthree")
# # => [["one", "two"], ["three"]]
# CSV.parse("one;two\n'three;'", separator: ';', quote_char: '\'')
Expand All @@ -79,6 +81,8 @@ class CSV
# See `CSV.parse` about the *separator* and *quote_char* arguments.
#
# ```
# require "csv"
#
# CSV.each_row("one,two\nthree") do |row|
# puts row
# end
Expand All @@ -101,6 +105,8 @@ class CSV
# See `CSV.parse` about the *separator* and *quote_char* arguments.
#
# ```
# require "csv"
#
# rows = CSV.each_row("one,two\nthree")
# rows.next # => ["one", "two"]
# rows.next # => ["three"]
Expand All @@ -114,6 +120,8 @@ class CSV
# Takes optional *quoting* argument to define quote behavior.
#
# ```
# require "csv"
#
# result = CSV.build do |csv|
# csv.row "one", "two"
# csv.row "three"
Expand All @@ -137,6 +145,8 @@ class CSV
# that writes to the given `IO`.
#
# ```
# require "csv"
#
# io = IO::Memory.new
# io.puts "HEADER"
# CSV.build(io) do |csv|
Expand Down
11 changes: 11 additions & 0 deletions src/digest/base.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ abstract class Digest::Base
# method available. Returns the resulting digest afterwards.
#
# ```
# require "digest/md5"
#
# digest = Digest::MD5.digest do |ctx|
# ctx.update "f"
# ctx.update "oo"
Expand All @@ -28,6 +30,8 @@ abstract class Digest::Base
# Returns the hexadecimal representation of the hash of *data*.
#
# ```
# require "digest/md5"
#
# Digest::MD5.hexdigest("foo") # => "acbd18db4cc2f85cedef654fccc4a4d8"
# ```
def self.hexdigest(data) : String
Expand All @@ -39,6 +43,9 @@ abstract class Digest::Base
# afterwards.
#
# ```
# require "digest/md5"
#
# Digest::MD5.hexdigest("foo") # => "acbd18db4cc2f85cedef654fccc4a4d8"
# Digest::MD5.hexdigest do |ctx|
# ctx.update "f"
# ctx.update "oo"
Expand All @@ -56,6 +63,8 @@ abstract class Digest::Base
# Returns the base64-encoded hash of *data*.
#
# ```
# require "digest/sha1"
#
# Digest::SHA1.base64digest("foo") # => "C+7Hteo/D9vJXQ3UfzxbwnXaijM="
# ```
def self.base64digest(data) : String
Expand All @@ -65,6 +74,8 @@ abstract class Digest::Base
# Returns the base64-encoded hash of *data*.
#
# ```
# require "digest/sha1"
#
# Digest::SHA1.base64digest do |ctx|
# ctx.update "f"
# ctx.update "oo"
Expand Down
Loading

0 comments on commit 29cb212

Please sign in to comment.