rbs 4.0.0.dev.4 → 4.0.0.dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +11 -8
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +17 -34
- data/.github/workflows/typecheck.yml +2 -2
- data/.github/workflows/valgrind.yml +42 -0
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +1 -1
- data/README.md +1 -1
- data/Rakefile +32 -5
- data/config.yml +46 -0
- data/core/array.rbs +96 -46
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/comparable.rbs +13 -6
- data/core/complex.rbs +55 -41
- data/core/dir.rbs +4 -4
- data/core/encoding.rbs +7 -10
- data/core/enumerable.rbs +90 -3
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +63 -1
- data/core/errno.rbs +8 -0
- data/core/errors.rbs +28 -1
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +40 -20
- data/core/file.rbs +108 -78
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +225 -69
- data/core/gc.rbs +417 -281
- data/core/hash.rbs +1023 -727
- data/core/integer.rbs +104 -110
- data/core/io/buffer.rbs +21 -10
- data/core/io/wait.rbs +11 -33
- data/core/io.rbs +82 -19
- data/core/kernel.rbs +70 -59
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +42 -3
- data/core/method.rbs +63 -27
- data/core/module.rbs +103 -26
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +43 -35
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +21 -15
- data/core/pathname.rbs +1272 -0
- data/core/proc.rbs +30 -25
- data/core/process.rbs +4 -2
- data/core/ractor.rbs +361 -509
- data/core/random.rbs +17 -0
- data/core/range.rbs +113 -16
- data/core/rational.rbs +56 -85
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +4 -113
- data/core/regexp.rbs +25 -20
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +6 -4
- data/core/rubygems/errors.rbs +3 -70
- data/core/rubygems/rubygems.rbs +11 -79
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +488 -359
- data/core/signal.rbs +24 -14
- data/core/string.rbs +3171 -1241
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +17 -11
- data/core/thread.rbs +95 -33
- data/core/time.rbs +35 -9
- data/core/trace_point.rbs +7 -4
- data/core/unbound_method.rbs +14 -6
- data/docs/aliases.md +79 -0
- data/docs/collection.md +2 -2
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +470 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +33 -4
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +77 -3
- data/ext/rbs_extension/ast_translation.h +3 -0
- data/ext/rbs_extension/class_constants.c +8 -2
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/extconf.rb +5 -1
- data/ext/rbs_extension/legacy_location.c +5 -5
- data/ext/rbs_extension/main.c +37 -20
- data/include/rbs/ast.h +85 -38
- data/include/rbs/defines.h +27 -0
- data/include/rbs/lexer.h +30 -11
- data/include/rbs/parser.h +6 -6
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -1
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +137 -0
- data/lib/rbs/ast/ruby/comment_block.rb +24 -0
- data/lib/rbs/ast/ruby/declarations.rb +198 -3
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/members.rb +159 -1
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +20 -15
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -51
- data/lib/rbs/cli.rb +52 -19
- data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +20 -0
- data/lib/rbs/definition_builder.rb +91 -2
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +227 -74
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -7
- data/lib/rbs/inline_parser.rb +341 -5
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/parser_aux.rb +2 -2
- data/lib/rbs/prototype/rb.rb +2 -2
- data/lib/rbs/prototype/rbi.rb +2 -0
- data/lib/rbs/prototype/runtime.rb +8 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +116 -38
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +16 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +27 -27
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +3 -2
- data/schema/typeParam.json +17 -1
- data/sig/ast/ruby/annotations.rbs +124 -0
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +87 -1
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +13 -4
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -1
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser.rbs +39 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -1
- data/sig/method_builder.rbs +3 -1
- data/sig/method_types.rbs +1 -1
- data/sig/parser.rbs +16 -2
- data/sig/resolver/type_name_resolver.rbs +35 -7
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- data/sig/types.rbs +4 -4
- data/src/ast.c +80 -1
- data/src/lexer.c +1392 -1313
- data/src/lexer.re +3 -0
- data/src/lexstate.c +58 -37
- data/src/location.c +4 -4
- data/src/parser.c +412 -145
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -71
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -10
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +3 -1
- data/stdlib/date/0/date.rbs +67 -59
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +737 -347
- data/stdlib/fileutils/0/fileutils.rbs +20 -14
- data/stdlib/forwardable/0/forwardable.rbs +3 -0
- data/stdlib/json/0/json.rbs +82 -28
- data/stdlib/net-http/0/net-http.rbs +3 -0
- data/stdlib/objspace/0/objspace.rbs +9 -27
- data/stdlib/open-uri/0/open-uri.rbs +40 -0
- data/stdlib/open3/0/open3.rbs +459 -1
- data/stdlib/openssl/0/openssl.rbs +331 -228
- data/stdlib/optparse/0/optparse.rbs +8 -3
- data/stdlib/pathname/0/pathname.rbs +9 -1379
- data/stdlib/psych/0/psych.rbs +4 -4
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +2 -2
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +6 -19
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/socket.rbs +13 -1
- data/stdlib/socket/0/tcp_socket.rbs +10 -2
- data/stdlib/stringio/0/stringio.rbs +1176 -85
- data/stdlib/strscan/0/string_scanner.rbs +31 -31
- data/stdlib/tempfile/0/tempfile.rbs +3 -3
- data/stdlib/time/0/time.rbs +1 -1
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/uri/0/common.rbs +16 -2
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +24 -16
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
- data/stdlib/zlib/0/gzip_reader.rbs +2 -2
- data/stdlib/zlib/0/gzip_writer.rbs +1 -1
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +30 -4
data/core/random.rbs
CHANGED
|
@@ -96,6 +96,23 @@ class Random < RBS::Unnamed::Random_Base
|
|
|
96
96
|
| (Float | ::Range[Float] max) -> Float
|
|
97
97
|
| [T < Numeric] (::Range[T]) -> T
|
|
98
98
|
|
|
99
|
+
# <!--
|
|
100
|
+
# rdoc-file=random.c
|
|
101
|
+
# - Random.seed -> integer
|
|
102
|
+
# -->
|
|
103
|
+
# Returns the seed value used to initialize the Ruby system PRNG. This may be
|
|
104
|
+
# used to initialize another generator with the same state at a later time,
|
|
105
|
+
# causing it to produce the same sequence of numbers.
|
|
106
|
+
#
|
|
107
|
+
# Random.seed #=> 1234
|
|
108
|
+
# prng1 = Random.new(Random.seed)
|
|
109
|
+
# prng1.seed #=> 1234
|
|
110
|
+
# prng1.rand(100) #=> 47
|
|
111
|
+
# Random.seed #=> 1234
|
|
112
|
+
# Random.rand(100) #=> 47
|
|
113
|
+
#
|
|
114
|
+
def self.seed: () -> ::Integer
|
|
115
|
+
|
|
99
116
|
# <!--
|
|
100
117
|
# rdoc-file=random.c
|
|
101
118
|
# - srand(number = Random.new_seed) -> old_seed
|
data/core/range.rbs
CHANGED
|
@@ -86,14 +86,14 @@
|
|
|
86
86
|
# end
|
|
87
87
|
# a # => [2, 4, 6, 8, 10]
|
|
88
88
|
#
|
|
89
|
-
# A range can be both beginless and endless.
|
|
89
|
+
# A range can be both beginless and endless. For literal beginless, endless
|
|
90
90
|
# ranges, at least the beginning or end of the range must be given as an
|
|
91
91
|
# explicit nil value. It is recommended to use an explicit nil beginning and
|
|
92
|
-
#
|
|
92
|
+
# end, since that is what Ruby uses for Range#inspect:
|
|
93
93
|
#
|
|
94
|
-
# (nil..) # => (nil..)
|
|
95
|
-
# (..nil) # => (nil..)
|
|
96
|
-
# (nil..nil) # => (nil..)
|
|
94
|
+
# (nil..) # => (nil..nil)
|
|
95
|
+
# (..nil) # => (nil..nil)
|
|
96
|
+
# (nil..nil) # => (nil..nil)
|
|
97
97
|
#
|
|
98
98
|
# ## Ranges and Other Classes
|
|
99
99
|
#
|
|
@@ -351,7 +351,7 @@ class Range[out Elem] < Object
|
|
|
351
351
|
# -->
|
|
352
352
|
# Returns an element from `self` selected by a binary search.
|
|
353
353
|
#
|
|
354
|
-
# See [Binary Searching](rdoc-ref:bsearch.rdoc).
|
|
354
|
+
# See [Binary Searching](rdoc-ref:language/bsearch.rdoc).
|
|
355
355
|
#
|
|
356
356
|
def bsearch: () -> ::Enumerator[Elem, Elem?]
|
|
357
357
|
| () { (Elem) -> (true | false) } -> Elem?
|
|
@@ -741,10 +741,7 @@ class Range[out Elem] < Object
|
|
|
741
741
|
#
|
|
742
742
|
# Related: Range#min, Range#minmax.
|
|
743
743
|
#
|
|
744
|
-
def max:
|
|
745
|
-
| () { (Elem a, Elem b) -> Integer } -> Elem
|
|
746
|
-
| (Integer n) -> ::Array[Elem]
|
|
747
|
-
| (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
|
|
744
|
+
def max: ...
|
|
748
745
|
|
|
749
746
|
# <!--
|
|
750
747
|
# rdoc-file=range.c
|
|
@@ -826,10 +823,52 @@ class Range[out Elem] < Object
|
|
|
826
823
|
#
|
|
827
824
|
# Related: Range#max, Range#minmax.
|
|
828
825
|
#
|
|
829
|
-
def min:
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
826
|
+
def min: ...
|
|
827
|
+
|
|
828
|
+
# <!--
|
|
829
|
+
# rdoc-file=range.c
|
|
830
|
+
# - minmax -> [object, object]
|
|
831
|
+
# - minmax {|a, b| ... } -> [object, object]
|
|
832
|
+
# -->
|
|
833
|
+
# Returns a 2-element array containing the minimum and maximum value in `self`,
|
|
834
|
+
# either according to comparison method `#<=>` or a given block.
|
|
835
|
+
#
|
|
836
|
+
# With no block given, returns the minimum and maximum values, using `#<=>` for
|
|
837
|
+
# comparison:
|
|
838
|
+
#
|
|
839
|
+
# (1..4).minmax # => [1, 4]
|
|
840
|
+
# (1...4).minmax # => [1, 3]
|
|
841
|
+
# ('a'..'d').minmax # => ["a", "d"]
|
|
842
|
+
# (-4..-1).minmax # => [-4, -1]
|
|
843
|
+
#
|
|
844
|
+
# With a block given, the block must return an integer:
|
|
845
|
+
#
|
|
846
|
+
# * Negative if `a` is smaller than `b`.
|
|
847
|
+
# * Zero if `a` and `b` are equal.
|
|
848
|
+
# * Positive if `a` is larger than `b`.
|
|
849
|
+
#
|
|
850
|
+
# The block is called `self.size` times to compare elements; returns a 2-element
|
|
851
|
+
# Array containing the minimum and maximum values from `self`, per the block:
|
|
852
|
+
#
|
|
853
|
+
# (1..4).minmax {|a, b| -(a <=> b) } # => [4, 1]
|
|
854
|
+
#
|
|
855
|
+
# Returns `[nil, nil]` if:
|
|
856
|
+
#
|
|
857
|
+
# * The begin value of the range is larger than the end value:
|
|
858
|
+
#
|
|
859
|
+
# (4..1).minmax # => [nil, nil]
|
|
860
|
+
# (4..1).minmax {|a, b| -(a <=> b) } # => [nil, nil]
|
|
861
|
+
#
|
|
862
|
+
# * The begin value of an exclusive range is equal to the end value:
|
|
863
|
+
#
|
|
864
|
+
# (1...1).minmax # => [nil, nil]
|
|
865
|
+
# (1...1).minmax {|a, b| -(a <=> b) } # => [nil, nil]
|
|
866
|
+
#
|
|
867
|
+
# Raises an exception if `self` is a beginless or an endless range.
|
|
868
|
+
#
|
|
869
|
+
# Related: Range#min, Range#max.
|
|
870
|
+
#
|
|
871
|
+
def minmax: ...
|
|
833
872
|
|
|
834
873
|
# <!--
|
|
835
874
|
# rdoc-file=range.c
|
|
@@ -936,8 +975,43 @@ class Range[out Elem] < Object
|
|
|
936
975
|
#
|
|
937
976
|
# Related: Range#count.
|
|
938
977
|
#
|
|
939
|
-
def size: () -> Integer
|
|
940
|
-
|
|
978
|
+
def size: () -> (Integer | Float | nil)
|
|
979
|
+
|
|
980
|
+
# <!--
|
|
981
|
+
# rdoc-file=range.c
|
|
982
|
+
# - count -> integer
|
|
983
|
+
# - count(object) -> integer
|
|
984
|
+
# - count {|element| ... } -> integer
|
|
985
|
+
# -->
|
|
986
|
+
# Returns the count of elements, based on an argument or block criterion, if
|
|
987
|
+
# given.
|
|
988
|
+
#
|
|
989
|
+
# With no argument and no block given, returns the number of elements:
|
|
990
|
+
#
|
|
991
|
+
# (1..4).count # => 4
|
|
992
|
+
# (1...4).count # => 3
|
|
993
|
+
# ('a'..'d').count # => 4
|
|
994
|
+
# ('a'...'d').count # => 3
|
|
995
|
+
# (1..).count # => Infinity
|
|
996
|
+
# (..4).count # => Infinity
|
|
997
|
+
#
|
|
998
|
+
# With argument `object`, returns the number of `object` found in `self`, which
|
|
999
|
+
# will usually be zero or one:
|
|
1000
|
+
#
|
|
1001
|
+
# (1..4).count(2) # => 1
|
|
1002
|
+
# (1..4).count(5) # => 0
|
|
1003
|
+
# (1..4).count('a') # => 0
|
|
1004
|
+
#
|
|
1005
|
+
# With a block given, calls the block with each element; returns the number of
|
|
1006
|
+
# elements for which the block returns a truthy value:
|
|
1007
|
+
#
|
|
1008
|
+
# (1..4).count {|element| element < 3 } # => 2
|
|
1009
|
+
#
|
|
1010
|
+
# Related: Range#size.
|
|
1011
|
+
#
|
|
1012
|
+
def count: () -> (Integer | Float)
|
|
1013
|
+
| (untyped) -> Integer
|
|
1014
|
+
| () { (Elem) -> boolish } -> Integer
|
|
941
1015
|
|
|
942
1016
|
# <!--
|
|
943
1017
|
# rdoc-file=range.c
|
|
@@ -1104,4 +1178,27 @@ class Range[out Elem] < Object
|
|
|
1104
1178
|
# Related: Range#cover?.
|
|
1105
1179
|
#
|
|
1106
1180
|
def member?: (untyped obj) -> bool
|
|
1181
|
+
|
|
1182
|
+
# <!--
|
|
1183
|
+
# rdoc-file=range.c
|
|
1184
|
+
# - to_a -> array
|
|
1185
|
+
# -->
|
|
1186
|
+
# Returns an array containing the elements in `self`, if a finite collection;
|
|
1187
|
+
# raises an exception otherwise.
|
|
1188
|
+
#
|
|
1189
|
+
# (1..4).to_a # => [1, 2, 3, 4]
|
|
1190
|
+
# (1...4).to_a # => [1, 2, 3]
|
|
1191
|
+
# ('a'..'d').to_a # => ["a", "b", "c", "d"]
|
|
1192
|
+
#
|
|
1193
|
+
def to_a: ...
|
|
1194
|
+
|
|
1195
|
+
# <!-- rdoc-file=range.c -->
|
|
1196
|
+
# Returns an array containing the elements in `self`, if a finite collection;
|
|
1197
|
+
# raises an exception otherwise.
|
|
1198
|
+
#
|
|
1199
|
+
# (1..4).to_a # => [1, 2, 3, 4]
|
|
1200
|
+
# (1...4).to_a # => [1, 2, 3]
|
|
1201
|
+
# ('a'..'d').to_a # => ["a", "b", "c", "d"]
|
|
1202
|
+
#
|
|
1203
|
+
alias entries to_a
|
|
1107
1204
|
end
|
data/core/rational.rbs
CHANGED
|
@@ -53,15 +53,16 @@ class Rational < Numeric
|
|
|
53
53
|
|
|
54
54
|
# <!--
|
|
55
55
|
# rdoc-file=rational.c
|
|
56
|
-
# -
|
|
56
|
+
# - self * other -> numeric
|
|
57
57
|
# -->
|
|
58
|
-
#
|
|
58
|
+
# Returns the numeric product of `self` and `other`:
|
|
59
59
|
#
|
|
60
|
-
# Rational(
|
|
61
|
-
# Rational(
|
|
62
|
-
# Rational(
|
|
63
|
-
# Rational(
|
|
64
|
-
# Rational(
|
|
60
|
+
# Rational(9, 8) * 4 #=> (9/2)
|
|
61
|
+
# Rational(20, 9) * 9.8 #=> 21.77777777777778
|
|
62
|
+
# Rational(9, 8) * Complex(1, 2) # => ((9/8)+(9/4)*i)
|
|
63
|
+
# Rational(2, 3) * Rational(2, 3) #=> (4/9)
|
|
64
|
+
# Rational(900) * Rational(1) #=> (900/1)
|
|
65
|
+
# Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
|
|
65
66
|
#
|
|
66
67
|
def *: (Integer) -> Rational
|
|
67
68
|
| (Rational) -> Rational
|
|
@@ -69,9 +70,9 @@ class Rational < Numeric
|
|
|
69
70
|
|
|
70
71
|
# <!--
|
|
71
72
|
# rdoc-file=rational.c
|
|
72
|
-
# -
|
|
73
|
+
# - self ** exponent -> numeric
|
|
73
74
|
# -->
|
|
74
|
-
#
|
|
75
|
+
# Returns `self` raised to the power `exponent`:
|
|
75
76
|
#
|
|
76
77
|
# Rational(2) ** Rational(3) #=> (8/1)
|
|
77
78
|
# Rational(10) ** -2 #=> (1/100)
|
|
@@ -85,27 +86,35 @@ class Rational < Numeric
|
|
|
85
86
|
|
|
86
87
|
# <!--
|
|
87
88
|
# rdoc-file=rational.c
|
|
88
|
-
# -
|
|
89
|
+
# - self + other -> numeric
|
|
89
90
|
# -->
|
|
90
|
-
#
|
|
91
|
+
# Returns the sum of `self` and `other`:
|
|
91
92
|
#
|
|
92
|
-
# Rational(2, 3)
|
|
93
|
-
# Rational(
|
|
94
|
-
# Rational(
|
|
95
|
-
#
|
|
96
|
-
# Rational(
|
|
93
|
+
# Rational(2, 3) + 0 # => (2/3)
|
|
94
|
+
# Rational(2, 3) + 1 # => (5/3)
|
|
95
|
+
# Rational(2, 3) + -1 # => (-1/3)
|
|
96
|
+
#
|
|
97
|
+
# Rational(2, 3) + Complex(1, 0) # => ((5/3)+0i)
|
|
98
|
+
#
|
|
99
|
+
# Rational(2, 3) + Rational(1, 1) # => (5/3)
|
|
100
|
+
# Rational(2, 3) + Rational(3, 2) # => (13/6)
|
|
101
|
+
# Rational(2, 3) + Rational(3.0, 2.0) # => (13/6)
|
|
102
|
+
# Rational(2, 3) + Rational(3.1, 2.1) # => (30399297484750849/14186338826217063)
|
|
103
|
+
#
|
|
104
|
+
# For a computation involving Floats, the result may be inexact (see Float#+):
|
|
105
|
+
#
|
|
106
|
+
# Rational(2, 3) + 1.0 # => 1.6666666666666665
|
|
107
|
+
# Rational(2, 3) + Complex(1.0, 0.0) # => (1.6666666666666665+0.0i)
|
|
97
108
|
#
|
|
98
109
|
def +: (Float) -> Float
|
|
99
110
|
| (Complex) -> Complex
|
|
100
111
|
| (Numeric) -> Rational
|
|
101
112
|
|
|
102
|
-
def +@: () -> Rational
|
|
103
|
-
|
|
104
113
|
# <!--
|
|
105
114
|
# rdoc-file=rational.c
|
|
106
|
-
# -
|
|
115
|
+
# - self - other -> numeric
|
|
107
116
|
# -->
|
|
108
|
-
#
|
|
117
|
+
# Returns the difference of `self` and `other`:
|
|
109
118
|
#
|
|
110
119
|
# Rational(2, 3) - Rational(2, 3) #=> (0/1)
|
|
111
120
|
# Rational(900) - Rational(1) #=> (899/1)
|
|
@@ -119,18 +128,20 @@ class Rational < Numeric
|
|
|
119
128
|
|
|
120
129
|
# <!--
|
|
121
130
|
# rdoc-file=rational.c
|
|
122
|
-
# - -
|
|
131
|
+
# - -self -> rational
|
|
123
132
|
# -->
|
|
124
|
-
#
|
|
133
|
+
# Returns `self`, negated:
|
|
134
|
+
#
|
|
135
|
+
# -(1/3r) # => (-1/3)
|
|
136
|
+
# -(-1/3r) # => (1/3)
|
|
125
137
|
#
|
|
126
138
|
def -@: () -> Rational
|
|
127
139
|
|
|
128
140
|
# <!--
|
|
129
141
|
# rdoc-file=rational.c
|
|
130
|
-
# -
|
|
131
|
-
# - rat.quo(numeric) -> numeric
|
|
142
|
+
# - self / other -> numeric
|
|
132
143
|
# -->
|
|
133
|
-
#
|
|
144
|
+
# Returns the quotient of `self` and `other`:
|
|
134
145
|
#
|
|
135
146
|
# Rational(2, 3) / Rational(2, 3) #=> (1/1)
|
|
136
147
|
# Rational(900) / Rational(1) #=> (900/1)
|
|
@@ -144,20 +155,29 @@ class Rational < Numeric
|
|
|
144
155
|
|
|
145
156
|
# <!--
|
|
146
157
|
# rdoc-file=rational.c
|
|
147
|
-
# -
|
|
158
|
+
# - self <=> other -> -1, 0, 1, or nil
|
|
148
159
|
# -->
|
|
149
|
-
#
|
|
150
|
-
#
|
|
160
|
+
# Compares `self` and `other`.
|
|
161
|
+
#
|
|
162
|
+
# Returns:
|
|
163
|
+
#
|
|
164
|
+
# * `-1`, if `self` is less than `other`.
|
|
165
|
+
# * `0`, if the two values are the same.
|
|
166
|
+
# * `1`, if `self` is greater than `other`.
|
|
167
|
+
# * `nil`, if the two values are incomparable.
|
|
151
168
|
#
|
|
152
|
-
#
|
|
169
|
+
# Examples:
|
|
153
170
|
#
|
|
154
|
-
# Rational(2, 3) <=> Rational(
|
|
155
|
-
# Rational(
|
|
156
|
-
# Rational(2,
|
|
157
|
-
# Rational(
|
|
158
|
-
# Rational(
|
|
171
|
+
# Rational(2, 3) <=> Rational(4, 3) # => -1
|
|
172
|
+
# Rational(2, 1) <=> Rational(2, 1) # => 0
|
|
173
|
+
# Rational(2, 1) <=> 2 # => 0
|
|
174
|
+
# Rational(2, 1) <=> 2.0 # => 0
|
|
175
|
+
# Rational(2, 1) <=> Complex(2, 0) # => 0
|
|
176
|
+
# Rational(4, 3) <=> Rational(2, 3) # => 1
|
|
177
|
+
# Rational(4, 3) <=> :foo # => nil
|
|
159
178
|
#
|
|
160
|
-
#
|
|
179
|
+
# Class Rational includes module Comparable, each of whose methods uses
|
|
180
|
+
# Rational#<=> for comparison.
|
|
161
181
|
#
|
|
162
182
|
def <=>: (Integer | Rational) -> Integer
|
|
163
183
|
| (untyped) -> Integer?
|
|
@@ -188,12 +208,6 @@ class Rational < Numeric
|
|
|
188
208
|
#
|
|
189
209
|
def abs: () -> Rational
|
|
190
210
|
|
|
191
|
-
def abs2: () -> Rational
|
|
192
|
-
|
|
193
|
-
def angle: () -> (Integer | Float)
|
|
194
|
-
|
|
195
|
-
alias arg angle
|
|
196
|
-
|
|
197
211
|
# <!--
|
|
198
212
|
# rdoc-file=rational.c
|
|
199
213
|
# - rat.ceil([ndigits]) -> integer or rational
|
|
@@ -222,10 +236,6 @@ class Rational < Numeric
|
|
|
222
236
|
|
|
223
237
|
def coerce: (Numeric) -> [ Numeric, Numeric ]
|
|
224
238
|
|
|
225
|
-
def conj: () -> Rational
|
|
226
|
-
|
|
227
|
-
def conjugate: () -> Rational
|
|
228
|
-
|
|
229
239
|
# <!--
|
|
230
240
|
# rdoc-file=rational.c
|
|
231
241
|
# - rat.denominator -> integer
|
|
@@ -239,15 +249,9 @@ class Rational < Numeric
|
|
|
239
249
|
#
|
|
240
250
|
def denominator: () -> Integer
|
|
241
251
|
|
|
242
|
-
def div: (Numeric) -> Integer
|
|
243
|
-
|
|
244
252
|
def divmod: (Integer | Float | Rational) -> [ Integer, Rational ]
|
|
245
253
|
| (Numeric) -> [ Numeric, Numeric ]
|
|
246
254
|
|
|
247
|
-
def dup: () -> self
|
|
248
|
-
|
|
249
|
-
def eql?: (untyped) -> bool
|
|
250
|
-
|
|
251
255
|
# <!--
|
|
252
256
|
# rdoc-file=rational.c
|
|
253
257
|
# - rat.fdiv(numeric) -> float
|
|
@@ -260,8 +264,6 @@ class Rational < Numeric
|
|
|
260
264
|
#
|
|
261
265
|
def fdiv: (Numeric) -> Float
|
|
262
266
|
|
|
263
|
-
def finite?: () -> bool
|
|
264
|
-
|
|
265
267
|
# <!--
|
|
266
268
|
# rdoc-file=rational.c
|
|
267
269
|
# - rat.floor([ndigits]) -> integer or rational
|
|
@@ -295,14 +297,6 @@ class Rational < Numeric
|
|
|
295
297
|
#
|
|
296
298
|
def hash: () -> Integer
|
|
297
299
|
|
|
298
|
-
def i: () -> Complex
|
|
299
|
-
|
|
300
|
-
def imag: () -> Integer
|
|
301
|
-
|
|
302
|
-
def imaginary: () -> Integer
|
|
303
|
-
|
|
304
|
-
def infinite?: () -> Integer?
|
|
305
|
-
|
|
306
300
|
# <!--
|
|
307
301
|
# rdoc-file=rational.c
|
|
308
302
|
# - rat.inspect -> string
|
|
@@ -315,8 +309,6 @@ class Rational < Numeric
|
|
|
315
309
|
#
|
|
316
310
|
def inspect: () -> String
|
|
317
311
|
|
|
318
|
-
def integer?: () -> bool
|
|
319
|
-
|
|
320
312
|
# <!-- rdoc-file=rational.c -->
|
|
321
313
|
# Returns the absolute value of `rat`.
|
|
322
314
|
#
|
|
@@ -336,8 +328,6 @@ class Rational < Numeric
|
|
|
336
328
|
#
|
|
337
329
|
def negative?: () -> bool
|
|
338
330
|
|
|
339
|
-
def nonzero?: () -> self?
|
|
340
|
-
|
|
341
331
|
# <!--
|
|
342
332
|
# rdoc-file=rational.c
|
|
343
333
|
# - rat.numerator -> integer
|
|
@@ -351,8 +341,6 @@ class Rational < Numeric
|
|
|
351
341
|
#
|
|
352
342
|
def numerator: () -> Integer
|
|
353
343
|
|
|
354
|
-
alias phase angle
|
|
355
|
-
|
|
356
344
|
def polar: () -> [ Rational, Integer | Float ]
|
|
357
345
|
|
|
358
346
|
# <!--
|
|
@@ -364,7 +352,7 @@ class Rational < Numeric
|
|
|
364
352
|
def positive?: () -> bool
|
|
365
353
|
|
|
366
354
|
# <!-- rdoc-file=rational.c -->
|
|
367
|
-
#
|
|
355
|
+
# Returns the quotient of `self` and `other`:
|
|
368
356
|
#
|
|
369
357
|
# Rational(2, 3) / Rational(2, 3) #=> (1/1)
|
|
370
358
|
# Rational(900) / Rational(1) #=> (900/1)
|
|
@@ -391,14 +379,8 @@ class Rational < Numeric
|
|
|
391
379
|
#
|
|
392
380
|
def rationalize: (?Numeric eps) -> Rational
|
|
393
381
|
|
|
394
|
-
def real: () -> Rational
|
|
395
|
-
|
|
396
|
-
def real?: () -> true
|
|
397
|
-
|
|
398
382
|
def rect: () -> [ Rational, Numeric ]
|
|
399
383
|
|
|
400
|
-
alias rectangular rect
|
|
401
|
-
|
|
402
384
|
def remainder: (Float) -> Float
|
|
403
385
|
| (Numeric) -> Rational
|
|
404
386
|
|
|
@@ -440,13 +422,6 @@ class Rational < Numeric
|
|
|
440
422
|
def round: (?half: :up | :down | :even) -> Integer
|
|
441
423
|
| (Integer digits, ?half: :up | :down | :even) -> (Integer | Rational)
|
|
442
424
|
|
|
443
|
-
def step: (?Numeric limit, ?Numeric step) { (Rational) -> void } -> self
|
|
444
|
-
| (?Numeric limit, ?Numeric step) -> Enumerator[Rational, self]
|
|
445
|
-
| (?by: Numeric, ?to: Numeric) { (Rational) -> void } -> self
|
|
446
|
-
| (?by: Numeric, ?to: Numeric) -> Enumerator[Rational, self]
|
|
447
|
-
|
|
448
|
-
def to_c: () -> Complex
|
|
449
|
-
|
|
450
425
|
# <!--
|
|
451
426
|
# rdoc-file=rational.c
|
|
452
427
|
# - rat.to_f -> float
|
|
@@ -476,8 +451,6 @@ class Rational < Numeric
|
|
|
476
451
|
#
|
|
477
452
|
def to_i: () -> Integer
|
|
478
453
|
|
|
479
|
-
alias to_int to_i
|
|
480
|
-
|
|
481
454
|
# <!--
|
|
482
455
|
# rdoc-file=rational.c
|
|
483
456
|
# - rat.to_r -> self
|
|
@@ -526,6 +499,4 @@ class Rational < Numeric
|
|
|
526
499
|
#
|
|
527
500
|
def truncate: () -> Integer
|
|
528
501
|
| (Integer ndigits) -> (Integer | Rational)
|
|
529
|
-
|
|
530
|
-
def zero?: () -> bool
|
|
531
502
|
end
|
data/core/rbs/unnamed/argf.rbs
CHANGED
|
@@ -93,7 +93,7 @@ module RBS
|
|
|
93
93
|
# * File `t.rb`:
|
|
94
94
|
#
|
|
95
95
|
# p "ARGV: #{ARGV}"
|
|
96
|
-
# p "
|
|
96
|
+
# p "Read: #{ARGF.read}" # Read everything from all specified streams.
|
|
97
97
|
#
|
|
98
98
|
# * Command and output:
|
|
99
99
|
#
|
|
@@ -836,7 +836,7 @@ module RBS
|
|
|
836
836
|
# Formats and writes `objects` to the stream.
|
|
837
837
|
#
|
|
838
838
|
# For details on `format_string`, see [Format
|
|
839
|
-
# Specifications](rdoc-ref:format_specifications.rdoc).
|
|
839
|
+
# Specifications](rdoc-ref:language/format_specifications.rdoc).
|
|
840
840
|
#
|
|
841
841
|
%a{annotate:rdoc:copy:ARGF#printf}
|
|
842
842
|
def printf: (String format_string, *untyped args) -> nil
|
|
@@ -140,7 +140,7 @@ module RBS
|
|
|
140
140
|
#
|
|
141
141
|
# * ::assoc: Returns a 2-element array containing the name and value of the
|
|
142
142
|
# named environment variable if it exists:
|
|
143
|
-
# * ::clone:
|
|
143
|
+
# * ::clone: Raises an exception.
|
|
144
144
|
# * ::except: Returns a hash of all name/value pairs except those given.
|
|
145
145
|
# * ::fetch: Returns the value for the given name.
|
|
146
146
|
# * ::inspect: Returns the contents of `ENV` as a string.
|
data/core/rbs/unnamed/random.rbs
CHANGED
|
@@ -31,9 +31,11 @@ module RBS
|
|
|
31
31
|
# prng.rand(100) # => 42
|
|
32
32
|
#
|
|
33
33
|
# When `max` is a Float, `rand` returns a random floating point number between
|
|
34
|
-
# 0.0 and `max`, including 0.0 and excluding `max`.
|
|
34
|
+
# 0.0 and `max`, including 0.0 and excluding `max`. Note that it behaves
|
|
35
|
+
# differently from Kernel.rand.
|
|
35
36
|
#
|
|
36
|
-
# prng.rand(1.5)
|
|
37
|
+
# prng.rand(1.5) # => 1.4600282860034115
|
|
38
|
+
# rand(1.5) # => 0
|
|
37
39
|
#
|
|
38
40
|
# When `range` is a Range, `rand` returns a random number where
|
|
39
41
|
# `range.member?(number) == true`.
|
|
@@ -146,56 +148,6 @@ module RBS
|
|
|
146
148
|
#
|
|
147
149
|
%a{annotate:rdoc:copy:Random::Formatter}
|
|
148
150
|
module Random_Formatter
|
|
149
|
-
# <!--
|
|
150
|
-
# rdoc-file=lib/random/formatter.rb
|
|
151
|
-
# - base64(n=nil)
|
|
152
|
-
# -->
|
|
153
|
-
# Generate a random base64 string.
|
|
154
|
-
#
|
|
155
|
-
# The argument *n* specifies the length, in bytes, of the random number to be
|
|
156
|
-
# generated. The length of the result string is about 4/3 of *n*.
|
|
157
|
-
#
|
|
158
|
-
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
|
|
159
|
-
# future.
|
|
160
|
-
#
|
|
161
|
-
# The result may contain A-Z, a-z, 0-9, "+", "/" and "=".
|
|
162
|
-
#
|
|
163
|
-
# require 'random/formatter'
|
|
164
|
-
#
|
|
165
|
-
# Random.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A=="
|
|
166
|
-
# # or
|
|
167
|
-
# prng = Random.new
|
|
168
|
-
# prng.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="
|
|
169
|
-
#
|
|
170
|
-
# See RFC 3548 for the definition of base64.
|
|
171
|
-
#
|
|
172
|
-
%a{annotate:rdoc:copy:Random::Formatter#base64}
|
|
173
|
-
def base64: (?Integer? n) -> String
|
|
174
|
-
|
|
175
|
-
# <!--
|
|
176
|
-
# rdoc-file=lib/random/formatter.rb
|
|
177
|
-
# - hex(n=nil)
|
|
178
|
-
# -->
|
|
179
|
-
# Generate a random hexadecimal string.
|
|
180
|
-
#
|
|
181
|
-
# The argument *n* specifies the length, in bytes, of the random number to be
|
|
182
|
-
# generated. The length of the resulting hexadecimal string is twice of *n*.
|
|
183
|
-
#
|
|
184
|
-
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
|
|
185
|
-
# future.
|
|
186
|
-
#
|
|
187
|
-
# The result may contain 0-9 and a-f.
|
|
188
|
-
#
|
|
189
|
-
# require 'random/formatter'
|
|
190
|
-
#
|
|
191
|
-
# Random.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
|
|
192
|
-
# # or
|
|
193
|
-
# prng = Random.new
|
|
194
|
-
# prng.hex #=> "91dc3bfb4de5b11d029d376634589b61"
|
|
195
|
-
#
|
|
196
|
-
%a{annotate:rdoc:copy:Random::Formatter#hex}
|
|
197
|
-
def hex: (?Integer? n) -> String
|
|
198
|
-
|
|
199
151
|
# <!-- rdoc-file=random.c -->
|
|
200
152
|
# Generates formatted random number from raw random bytes. See Random#rand.
|
|
201
153
|
#
|
|
@@ -208,9 +160,6 @@ module RBS
|
|
|
208
160
|
| (::Range[Integer] n) -> Integer
|
|
209
161
|
| (::Range[Numeric] n) -> Numeric
|
|
210
162
|
|
|
211
|
-
%a{annotate:rdoc:copy:Random::Formatter#random_byte}
|
|
212
|
-
def random_bytes: (?Integer? n) -> String
|
|
213
|
-
|
|
214
163
|
# <!--
|
|
215
164
|
# rdoc-file=random.c
|
|
216
165
|
# - prng.random_number -> float
|
|
@@ -230,64 +179,6 @@ module RBS
|
|
|
230
179
|
| (?::Range[Float]? n) -> Float
|
|
231
180
|
| (?::Range[Integer]? n) -> Integer
|
|
232
181
|
| (?::Range[Numeric]? n) -> Numeric
|
|
233
|
-
|
|
234
|
-
# <!--
|
|
235
|
-
# rdoc-file=lib/random/formatter.rb
|
|
236
|
-
# - urlsafe_base64(n=nil, padding=false)
|
|
237
|
-
# -->
|
|
238
|
-
# Generate a random URL-safe base64 string.
|
|
239
|
-
#
|
|
240
|
-
# The argument *n* specifies the length, in bytes, of the random number to be
|
|
241
|
-
# generated. The length of the result string is about 4/3 of *n*.
|
|
242
|
-
#
|
|
243
|
-
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
|
|
244
|
-
# future.
|
|
245
|
-
#
|
|
246
|
-
# The boolean argument *padding* specifies the padding. If it is false or nil,
|
|
247
|
-
# padding is not generated. Otherwise padding is generated. By default, padding
|
|
248
|
-
# is not generated because "=" may be used as a URL delimiter.
|
|
249
|
-
#
|
|
250
|
-
# The result may contain A-Z, a-z, 0-9, "-" and "_". "=" is also used if
|
|
251
|
-
# *padding* is true.
|
|
252
|
-
#
|
|
253
|
-
# require 'random/formatter'
|
|
254
|
-
#
|
|
255
|
-
# Random.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
|
|
256
|
-
# # or
|
|
257
|
-
# prng = Random.new
|
|
258
|
-
# prng.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
|
|
259
|
-
#
|
|
260
|
-
# prng.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
|
|
261
|
-
# prng.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
|
|
262
|
-
#
|
|
263
|
-
# See RFC 3548 for the definition of URL-safe base64.
|
|
264
|
-
#
|
|
265
|
-
%a{annotate:rdoc:copy:Random::Formatter#urlsafe_base64}
|
|
266
|
-
def urlsafe_base64: (?Integer? n, ?boolish padding) -> String
|
|
267
|
-
|
|
268
|
-
# <!--
|
|
269
|
-
# rdoc-file=lib/random/formatter.rb
|
|
270
|
-
# - uuid()
|
|
271
|
-
# -->
|
|
272
|
-
# Generate a random v4 UUID (Universally Unique IDentifier).
|
|
273
|
-
#
|
|
274
|
-
# require 'random/formatter'
|
|
275
|
-
#
|
|
276
|
-
# Random.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
|
|
277
|
-
# Random.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
|
|
278
|
-
# # or
|
|
279
|
-
# prng = Random.new
|
|
280
|
-
# prng.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
|
|
281
|
-
#
|
|
282
|
-
# The version 4 UUID is purely random (except the version). It doesn't contain
|
|
283
|
-
# meaningful information such as MAC addresses, timestamps, etc.
|
|
284
|
-
#
|
|
285
|
-
# The result contains 122 random bits (15.25 random bytes).
|
|
286
|
-
#
|
|
287
|
-
# See [RFC9562](https://www.rfc-editor.org/rfc/rfc9562) for details of UUIDv4.
|
|
288
|
-
#
|
|
289
|
-
%a{annotate:rdoc:copy:Random::Formatter#uuid}
|
|
290
|
-
def uuid: () -> String
|
|
291
182
|
end
|
|
292
183
|
end
|
|
293
184
|
end
|