steep 0.11.1 → 0.12.0
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/workflows/ruby.yml +27 -0
- data/.gitmodules +3 -0
- data/CHANGELOG.md +5 -0
- data/README.md +48 -90
- data/Rakefile +10 -6
- data/Steepfile +1 -0
- data/bin/setup +1 -0
- data/bin/smoke_runner.rb +9 -14
- data/exe/rbs +3 -0
- data/exe/ruby-signature +3 -0
- data/exe/steep +1 -0
- data/lib/steep.rb +32 -26
- data/lib/steep/annotation_parser.rb +167 -0
- data/lib/steep/ast/annotation/collection.rb +7 -7
- data/lib/steep/ast/types.rb +60 -0
- data/lib/steep/ast/types/any.rb +1 -1
- data/lib/steep/ast/types/factory.rb +535 -0
- data/lib/steep/ast/types/name.rb +3 -3
- data/lib/steep/ast/types/var.rb +1 -1
- data/lib/steep/cli.rb +56 -240
- data/lib/steep/drivers/annotations.rb +36 -19
- data/lib/steep/drivers/check.rb +55 -91
- data/lib/steep/drivers/init.rb +54 -0
- data/lib/steep/drivers/langserver.rb +241 -150
- data/lib/steep/drivers/print_project.rb +56 -0
- data/lib/steep/drivers/signature_error_printer.rb +25 -0
- data/lib/steep/drivers/trace_printer.rb +25 -0
- data/lib/steep/drivers/utils/driver_helper.rb +26 -0
- data/lib/steep/drivers/validate.rb +18 -38
- data/lib/steep/drivers/vendor.rb +46 -0
- data/lib/steep/drivers/watch.rb +78 -140
- data/lib/steep/errors.rb +22 -13
- data/lib/steep/interface/interface.rb +91 -0
- data/lib/steep/interface/method.rb +0 -4
- data/lib/steep/interface/method_type.rb +362 -2
- data/lib/steep/interface/substitution.rb +22 -0
- data/lib/steep/project.rb +25 -233
- data/lib/steep/project/dsl.rb +132 -0
- data/lib/steep/project/file.rb +93 -76
- data/lib/steep/project/file_loader.rb +63 -0
- data/lib/steep/project/options.rb +7 -0
- data/lib/steep/project/target.rb +190 -0
- data/lib/steep/signature/errors.rb +25 -77
- data/lib/steep/signature/validator.rb +122 -0
- data/lib/steep/source.rb +12 -7
- data/lib/steep/subtyping/check.rb +357 -633
- data/lib/steep/subtyping/constraints.rb +2 -2
- data/lib/steep/subtyping/trace.rb +23 -0
- data/lib/steep/type_construction.rb +509 -455
- data/lib/steep/type_inference/constant_env.rb +16 -24
- data/lib/steep/type_inference/type_env.rb +26 -18
- data/lib/steep/version.rb +1 -1
- data/sample/Steepfile +6 -0
- data/sample/lib/conference.rb +12 -0
- data/sample/sig/conference.rbs +6 -0
- data/smoke/alias/Steepfile +4 -0
- data/smoke/alias/a.rb +2 -2
- data/smoke/alias/{a.rbi → a.rbs} +1 -1
- data/smoke/and/Steepfile +4 -0
- data/smoke/array/Steepfile +4 -0
- data/smoke/array/a.rb +2 -2
- data/smoke/array/b.rb +4 -4
- data/smoke/array/c.rb +2 -2
- data/smoke/block/Steepfile +5 -0
- data/smoke/block/{a.rbi → a.rbs} +1 -1
- data/smoke/block/{c.rbi → c.rbs} +0 -0
- data/smoke/block/d.rb +6 -6
- data/smoke/case/Steepfile +4 -0
- data/smoke/case/a.rb +4 -3
- data/smoke/class/Steepfile +4 -0
- data/smoke/class/a.rb +1 -4
- data/smoke/class/a.rbs +24 -0
- data/smoke/class/h.rb +6 -2
- data/smoke/class/{h.rbi → h.rbs} +1 -2
- data/smoke/class/i.rb +1 -2
- data/smoke/class/i.rbs +9 -0
- data/smoke/const/Steepfile +4 -0
- data/smoke/dstr/Steepfile +4 -0
- data/smoke/ensure/Steepfile +4 -0
- data/smoke/ensure/a.rb +1 -1
- data/smoke/enumerator/Steepfile +4 -0
- data/smoke/enumerator/a.rb +7 -7
- data/smoke/enumerator/b.rb +6 -6
- data/smoke/extension/Steepfile +4 -0
- data/smoke/extension/{a.rbi → a.rbs} +2 -2
- data/smoke/extension/{e.rbi → e.rbs} +2 -2
- data/smoke/hash/Steepfile +4 -0
- data/smoke/hash/{a.rbi → a.rbs} +0 -0
- data/smoke/hash/b.rb +2 -2
- data/smoke/hash/c.rb +1 -1
- data/smoke/hash/e.rbs +3 -0
- data/smoke/hash/f.rb +1 -1
- data/smoke/hello/Steepfile +4 -0
- data/smoke/hello/hello.rbs +7 -0
- data/smoke/if/Steepfile +4 -0
- data/smoke/implements/Steepfile +4 -0
- data/smoke/implements/a.rbs +6 -0
- data/smoke/initialize/Steepfile +4 -0
- data/smoke/initialize/a.rbs +3 -0
- data/smoke/integer/Steepfile +4 -0
- data/smoke/integer/a.rb +5 -3
- data/smoke/interface/Steepfile +4 -0
- data/smoke/interface/{a.rbi → a.rbs} +0 -0
- data/smoke/kwbegin/Steepfile +4 -0
- data/smoke/lambda/Steepfile +4 -0
- data/smoke/lambda/a.rb +9 -2
- data/smoke/literal/Steepfile +4 -0
- data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
- data/smoke/map/Steepfile +4 -0
- data/smoke/map/a.rb +1 -1
- data/smoke/method/Steepfile +4 -0
- data/smoke/method/{a.rbi → a.rbs} +0 -0
- data/smoke/method/b.rb +1 -4
- data/smoke/method/d.rb +1 -0
- data/smoke/method/d.rbs +3 -0
- data/smoke/module/Steepfile +4 -0
- data/smoke/module/a.rb +1 -1
- data/smoke/module/a.rbs +16 -0
- data/smoke/module/c.rb +1 -1
- data/smoke/regexp/Steepfile +4 -0
- data/smoke/regexp/a.rb +2 -2
- data/smoke/regexp/b.rb +16 -16
- data/smoke/regression/Steepfile +5 -0
- data/smoke/regression/array.rb +2 -2
- data/smoke/regression/hash.rb +2 -2
- data/smoke/regression/poly_new.rb +2 -0
- data/smoke/regression/poly_new.rbs +4 -0
- data/smoke/regression/set_divide.rb +2 -2
- data/smoke/rescue/Steepfile +4 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +4 -0
- data/smoke/self/a.rbs +4 -0
- data/smoke/skip/Steepfile +4 -0
- data/smoke/stdout/Steepfile +4 -0
- data/smoke/stdout/{a.rbi → a.rbs} +1 -1
- data/smoke/super/Steepfile +4 -0
- data/smoke/super/a.rbs +10 -0
- data/smoke/type_case/Steepfile +4 -0
- data/smoke/type_case/a.rb +1 -1
- data/smoke/yield/Steepfile +4 -0
- data/smoke/yield/a.rb +2 -2
- data/steep.gemspec +14 -7
- data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
- data/vendor/ruby-signature/.gitignore +12 -0
- data/vendor/ruby-signature/.rubocop.yml +15 -0
- data/vendor/ruby-signature/BSDL +22 -0
- data/vendor/ruby-signature/COPYING +56 -0
- data/vendor/ruby-signature/Gemfile +6 -0
- data/vendor/ruby-signature/README.md +93 -0
- data/vendor/ruby-signature/Rakefile +66 -0
- data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
- data/vendor/ruby-signature/bin/console +14 -0
- data/vendor/ruby-signature/bin/query-rdoc +103 -0
- data/vendor/ruby-signature/bin/setup +10 -0
- data/vendor/ruby-signature/bin/sort +88 -0
- data/vendor/ruby-signature/bin/test_runner.rb +17 -0
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
- data/vendor/ruby-signature/docs/sigs.md +148 -0
- data/vendor/ruby-signature/docs/stdlib.md +152 -0
- data/vendor/ruby-signature/docs/syntax.md +528 -0
- data/vendor/ruby-signature/exe/rbs +3 -0
- data/vendor/ruby-signature/exe/ruby-signature +7 -0
- data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
- data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
- data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
- data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
- metadata +244 -54
- data/.travis.yml +0 -7
- data/lib/steep/ast/signature/alias.rb +0 -19
- data/lib/steep/ast/signature/class.rb +0 -33
- data/lib/steep/ast/signature/const.rb +0 -17
- data/lib/steep/ast/signature/env.rb +0 -138
- data/lib/steep/ast/signature/extension.rb +0 -21
- data/lib/steep/ast/signature/gvar.rb +0 -17
- data/lib/steep/ast/signature/interface.rb +0 -31
- data/lib/steep/ast/signature/members.rb +0 -115
- data/lib/steep/ast/signature/module.rb +0 -21
- data/lib/steep/drivers/print_interface.rb +0 -94
- data/lib/steep/drivers/scaffold.rb +0 -321
- data/lib/steep/drivers/utils/each_signature.rb +0 -31
- data/lib/steep/interface/abstract.rb +0 -68
- data/lib/steep/interface/builder.rb +0 -637
- data/lib/steep/interface/instantiated.rb +0 -163
- data/lib/steep/interface/ivar_chain.rb +0 -26
- data/lib/steep/parser.y +0 -1278
- data/lib/steep/project/listener.rb +0 -53
- data/smoke/class/a.rbi +0 -24
- data/smoke/class/d.rb +0 -9
- data/smoke/class/e.rb +0 -12
- data/smoke/class/i.rbi +0 -9
- data/smoke/hash/e.rbi +0 -3
- data/smoke/hello/hello.rbi +0 -7
- data/smoke/implements/a.rbi +0 -6
- data/smoke/initialize/a.rbi +0 -3
- data/smoke/module/a.rbi +0 -16
- data/smoke/self/a.rbi +0 -4
- data/smoke/super/a.rbi +0 -10
- data/stdlib/builtin.rbi +0 -787
@@ -0,0 +1,710 @@
|
|
1
|
+
# Holds Integer values. You cannot add a singleton method to an Integer object,
|
2
|
+
# any attempt to do so will raise a TypeError.
|
3
|
+
#
|
4
|
+
class Integer < Numeric
|
5
|
+
# Returns the integer square root of the non-negative integer `n`, i.e. the
|
6
|
+
# largest non-negative integer less than or equal to the square root of `n`.
|
7
|
+
#
|
8
|
+
# Integer.sqrt(0) #=> 0
|
9
|
+
# Integer.sqrt(1) #=> 1
|
10
|
+
# Integer.sqrt(24) #=> 4
|
11
|
+
# Integer.sqrt(25) #=> 5
|
12
|
+
# Integer.sqrt(10**400) #=> 10**200
|
13
|
+
#
|
14
|
+
# Equivalent to `Math.sqrt(n).floor`, except that the result of the latter code
|
15
|
+
# may differ from the true value due to the limited precision of floating point
|
16
|
+
# arithmetic.
|
17
|
+
#
|
18
|
+
# Integer.sqrt(10**46) #=> 100000000000000000000000
|
19
|
+
# Math.sqrt(10**46).floor #=> 99999999999999991611392 (!)
|
20
|
+
#
|
21
|
+
# If `n` is not an Integer, it is converted to an Integer first. If `n` is
|
22
|
+
# negative, a Math::DomainError is raised.
|
23
|
+
#
|
24
|
+
def self.sqrt: (int n) -> Integer
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
# Returns `int` modulo `other`.
|
29
|
+
#
|
30
|
+
# See Numeric#divmod for more information.
|
31
|
+
#
|
32
|
+
def %: (Float) -> Float
|
33
|
+
| (Rational) -> Rational
|
34
|
+
| (Integer) -> Integer
|
35
|
+
| (Numeric) -> Numeric
|
36
|
+
|
37
|
+
# Bitwise AND.
|
38
|
+
#
|
39
|
+
def &: (Integer) -> Integer
|
40
|
+
|
41
|
+
# Performs multiplication: the class of the resulting object depends on the
|
42
|
+
# class of `numeric`.
|
43
|
+
#
|
44
|
+
def *: (Float) -> Float
|
45
|
+
| (Rational) -> Rational
|
46
|
+
| (Complex) -> Complex
|
47
|
+
| (Integer) -> Integer
|
48
|
+
| (Numeric) -> Numeric
|
49
|
+
|
50
|
+
# Raises `int` to the power of `numeric`, which may be negative or fractional.
|
51
|
+
# The result may be an Integer, a Float, a Rational, or a complex number.
|
52
|
+
#
|
53
|
+
# 2 ** 3 #=> 8
|
54
|
+
# 2 ** -1 #=> (1/2)
|
55
|
+
# 2 ** 0.5 #=> 1.4142135623730951
|
56
|
+
# (-1) ** 0.5 #=> (0.0+1.0i)
|
57
|
+
#
|
58
|
+
# 123456789 ** 2 #=> 15241578750190521
|
59
|
+
# 123456789 ** 1.2 #=> 5126464716.0993185
|
60
|
+
# 123456789 ** -2 #=> (1/15241578750190521)
|
61
|
+
#
|
62
|
+
def **: (Integer) -> Numeric
|
63
|
+
| (Float) -> Numeric
|
64
|
+
| (Rational) -> Numeric
|
65
|
+
| (Complex) -> Complex
|
66
|
+
| (Numeric) -> Numeric
|
67
|
+
|
68
|
+
# Performs addition: the class of the resulting object depends on the class of
|
69
|
+
# `numeric`.
|
70
|
+
#
|
71
|
+
def +: (Integer) -> Integer
|
72
|
+
| (Float) -> Float
|
73
|
+
| (Rational) -> Rational
|
74
|
+
| (Complex) -> Complex
|
75
|
+
| (Numeric) -> Numeric
|
76
|
+
|
77
|
+
def +@: () -> Integer
|
78
|
+
|
79
|
+
# Performs subtraction: the class of the resulting object depends on the class
|
80
|
+
# of `numeric`.
|
81
|
+
#
|
82
|
+
def -: (Integer) -> Integer
|
83
|
+
| (Float) -> Float
|
84
|
+
| (Rational) -> Rational
|
85
|
+
| (Complex) -> Complex
|
86
|
+
| (Numeric) -> Numeric
|
87
|
+
|
88
|
+
# Returns `int`, negated.
|
89
|
+
#
|
90
|
+
def -@: () -> Integer
|
91
|
+
|
92
|
+
# Performs division: the class of the resulting object depends on the class of
|
93
|
+
# `numeric`.
|
94
|
+
#
|
95
|
+
def /: (Integer) -> Integer
|
96
|
+
| (Float) -> Float
|
97
|
+
| (Rational) -> Rational
|
98
|
+
| (Complex) -> Complex
|
99
|
+
| (Numeric) -> Numeric
|
100
|
+
|
101
|
+
# Returns `true` if the value of `int` is less than that of `real`.
|
102
|
+
#
|
103
|
+
def <: (Numeric) -> bool
|
104
|
+
|
105
|
+
# Returns `int` shifted left `count` positions, or right if `count` is negative.
|
106
|
+
#
|
107
|
+
def <<: (int) -> Integer
|
108
|
+
|
109
|
+
# Returns `true` if the value of `int` is less than or equal to that of `real`.
|
110
|
+
#
|
111
|
+
def <=: (Numeric) -> bool
|
112
|
+
|
113
|
+
# Comparison---Returns -1, 0, or +1 depending on whether `int` is less than,
|
114
|
+
# equal to, or greater than `numeric`.
|
115
|
+
#
|
116
|
+
# This is the basis for the tests in the Comparable module.
|
117
|
+
#
|
118
|
+
# `nil` is returned if the two values are incomparable.
|
119
|
+
#
|
120
|
+
def <=>: (Numeric) -> Integer?
|
121
|
+
|
122
|
+
# Returns `true` if `int` equals `other` numerically. Contrast this with
|
123
|
+
# Integer#eql?, which requires `other` to be an Integer.
|
124
|
+
#
|
125
|
+
# 1 == 2 #=> false
|
126
|
+
# 1 == 1.0 #=> true
|
127
|
+
#
|
128
|
+
def ==: (untyped) -> bool
|
129
|
+
|
130
|
+
# Returns `true` if `int` equals `other` numerically. Contrast this with
|
131
|
+
# Integer#eql?, which requires `other` to be an Integer.
|
132
|
+
#
|
133
|
+
# 1 == 2 #=> false
|
134
|
+
# 1 == 1.0 #=> true
|
135
|
+
#
|
136
|
+
def ===: (untyped) -> bool
|
137
|
+
|
138
|
+
# Returns `true` if the value of `int` is greater than that of `real`.
|
139
|
+
#
|
140
|
+
def >: (Numeric) -> bool
|
141
|
+
|
142
|
+
# Returns `true` if the value of `int` is greater than or equal to that of
|
143
|
+
# `real`.
|
144
|
+
#
|
145
|
+
def >=: (Numeric) -> bool
|
146
|
+
|
147
|
+
# Returns `int` shifted right `count` positions, or left if `count` is negative.
|
148
|
+
#
|
149
|
+
def >>: (int) -> Integer
|
150
|
+
|
151
|
+
# Bit Reference---Returns the `n`th bit in the binary representation of `int`,
|
152
|
+
# where `int[0]` is the least significant bit.
|
153
|
+
#
|
154
|
+
# a = 0b11001100101010
|
155
|
+
# 30.downto(0) {|n| print a[n] }
|
156
|
+
# #=> 0000000000000000011001100101010
|
157
|
+
#
|
158
|
+
# a = 9**15
|
159
|
+
# 50.downto(0) {|n| print a[n] }
|
160
|
+
# #=> 000101110110100000111000011110010100111100010111001
|
161
|
+
#
|
162
|
+
# In principle, `n[i]` is equivalent to `(n >> i) & 1`. Thus, any negative index
|
163
|
+
# always returns zero:
|
164
|
+
#
|
165
|
+
# p 255[-1] #=> 0
|
166
|
+
#
|
167
|
+
# Range operations `n[i, len]` and `n[i..j]` are naturally extended.
|
168
|
+
#
|
169
|
+
# * `n[i, len]` equals to `(n >> i) & ((1 << len) - 1)`.
|
170
|
+
# * `n[i..j]` equals to `(n >> i) & ((1 << (j - i + 1)) - 1)`.
|
171
|
+
# * `n[i...j]` equals to `(n >> i) & ((1 << (j - i)) - 1)`.
|
172
|
+
# * `n[i..]` equals to `(n >> i)`.
|
173
|
+
# * `n[..j]` is zero if `n & ((1 << (j + 1)) - 1)` is zero. Otherwise, raises
|
174
|
+
# an ArgumentError.
|
175
|
+
# * `n[...j]` is zero if `n & ((1 << j) - 1)` is zero. Otherwise, raises an
|
176
|
+
# ArgumentError.
|
177
|
+
#
|
178
|
+
#
|
179
|
+
# Note that range operation may exhaust memory. For example, `-1[0,
|
180
|
+
# 1000000000000]` will raise NoMemoryError.
|
181
|
+
#
|
182
|
+
def []: (int) -> Integer
|
183
|
+
| (int i, int len) -> Integer
|
184
|
+
| (Range[int]) -> Integer
|
185
|
+
|
186
|
+
# Bitwise EXCLUSIVE OR.
|
187
|
+
#
|
188
|
+
def ^: (Integer) -> Integer
|
189
|
+
|
190
|
+
# Returns the absolute value of `int`.
|
191
|
+
#
|
192
|
+
# (-12345).abs #=> 12345
|
193
|
+
# -12345.abs #=> 12345
|
194
|
+
# 12345.abs #=> 12345
|
195
|
+
#
|
196
|
+
# Integer#magnitude is an alias for Integer#abs.
|
197
|
+
#
|
198
|
+
def abs: () -> Integer
|
199
|
+
|
200
|
+
def abs2: () -> Integer
|
201
|
+
|
202
|
+
# Returns `true` if all bits of `int & mask` are 1.
|
203
|
+
#
|
204
|
+
def allbits?: (int mask) -> bool
|
205
|
+
|
206
|
+
def angle: () -> (Integer | Float)
|
207
|
+
|
208
|
+
# Returns `true` if any bits of `int & mask` are 1.
|
209
|
+
#
|
210
|
+
def anybits?: (int mask) -> bool
|
211
|
+
|
212
|
+
alias arg angle
|
213
|
+
|
214
|
+
# Returns the number of bits of the value of `int`.
|
215
|
+
#
|
216
|
+
# "Number of bits" means the bit position of the highest bit which is different
|
217
|
+
# from the sign bit (where the least significant bit has bit position 1). If
|
218
|
+
# there is no such bit (zero or minus one), zero is returned.
|
219
|
+
#
|
220
|
+
# I.e. this method returns *ceil(log2(int < 0 ? -int : int+1))*.
|
221
|
+
#
|
222
|
+
# (-2**1000-1).bit_length #=> 1001
|
223
|
+
# (-2**1000).bit_length #=> 1000
|
224
|
+
# (-2**1000+1).bit_length #=> 1000
|
225
|
+
# (-2**12-1).bit_length #=> 13
|
226
|
+
# (-2**12).bit_length #=> 12
|
227
|
+
# (-2**12+1).bit_length #=> 12
|
228
|
+
# -0x101.bit_length #=> 9
|
229
|
+
# -0x100.bit_length #=> 8
|
230
|
+
# -0xff.bit_length #=> 8
|
231
|
+
# -2.bit_length #=> 1
|
232
|
+
# -1.bit_length #=> 0
|
233
|
+
# 0.bit_length #=> 0
|
234
|
+
# 1.bit_length #=> 1
|
235
|
+
# 0xff.bit_length #=> 8
|
236
|
+
# 0x100.bit_length #=> 9
|
237
|
+
# (2**12-1).bit_length #=> 12
|
238
|
+
# (2**12).bit_length #=> 13
|
239
|
+
# (2**12+1).bit_length #=> 13
|
240
|
+
# (2**1000-1).bit_length #=> 1000
|
241
|
+
# (2**1000).bit_length #=> 1001
|
242
|
+
# (2**1000+1).bit_length #=> 1001
|
243
|
+
#
|
244
|
+
# This method can be used to detect overflow in Array#pack as follows:
|
245
|
+
#
|
246
|
+
# if n.bit_length < 32
|
247
|
+
# [n].pack("l") # no overflow
|
248
|
+
# else
|
249
|
+
# raise "overflow"
|
250
|
+
# end
|
251
|
+
#
|
252
|
+
def bit_length: () -> Integer
|
253
|
+
|
254
|
+
# Returns the smallest number greater than or equal to `int` with a precision of
|
255
|
+
# `ndigits` decimal digits (default: 0).
|
256
|
+
#
|
257
|
+
# When the precision is negative, the returned value is an integer with at least
|
258
|
+
# `ndigits.abs` trailing zeros.
|
259
|
+
#
|
260
|
+
# Returns `self` when `ndigits` is zero or positive.
|
261
|
+
#
|
262
|
+
# 1.ceil #=> 1
|
263
|
+
# 1.ceil(2) #=> 1
|
264
|
+
# 18.ceil(-1) #=> 20
|
265
|
+
# (-18).ceil(-1) #=> -10
|
266
|
+
#
|
267
|
+
def ceil: () -> Integer
|
268
|
+
| (int digits) -> (Integer | Float)
|
269
|
+
|
270
|
+
# Returns a string containing the character represented by the `int`'s value
|
271
|
+
# according to `encoding`.
|
272
|
+
#
|
273
|
+
# 65.chr #=> "A"
|
274
|
+
# 230.chr #=> "\xE6"
|
275
|
+
# 255.chr(Encoding::UTF_8) #=> "\u00FF"
|
276
|
+
#
|
277
|
+
def chr: (?Encoding | string) -> String
|
278
|
+
|
279
|
+
def clone: (?freeze: bool) -> self
|
280
|
+
|
281
|
+
# Returns an array with both a `numeric` and a `big` represented as Bignum
|
282
|
+
# objects.
|
283
|
+
#
|
284
|
+
# This is achieved by converting `numeric` to a Bignum.
|
285
|
+
#
|
286
|
+
# A TypeError is raised if the `numeric` is not a Fixnum or Bignum type.
|
287
|
+
#
|
288
|
+
# (0x3FFFFFFFFFFFFFFF+1).coerce(42) #=> [42, 4611686018427387904]
|
289
|
+
#
|
290
|
+
def coerce: (Numeric) -> [Numeric, Numeric]
|
291
|
+
|
292
|
+
def conj: () -> Integer
|
293
|
+
|
294
|
+
def conjugate: () -> Integer
|
295
|
+
|
296
|
+
# Returns 1.
|
297
|
+
#
|
298
|
+
def denominator: () -> Integer
|
299
|
+
|
300
|
+
# Returns the digits of `int`'s place-value representation with radix `base`
|
301
|
+
# (default: 10). The digits are returned as an array with the least significant
|
302
|
+
# digit as the first array element.
|
303
|
+
#
|
304
|
+
# `base` must be greater than or equal to 2.
|
305
|
+
#
|
306
|
+
# 12345.digits #=> [5, 4, 3, 2, 1]
|
307
|
+
# 12345.digits(7) #=> [4, 6, 6, 0, 5]
|
308
|
+
# 12345.digits(100) #=> [45, 23, 1]
|
309
|
+
#
|
310
|
+
# -12345.digits(7) #=> Math::DomainError
|
311
|
+
#
|
312
|
+
def digits: (?int base) -> ::Array[Integer]
|
313
|
+
|
314
|
+
# Performs integer division: returns the integer result of dividing `int` by
|
315
|
+
# `numeric`.
|
316
|
+
#
|
317
|
+
def div: (Numeric) -> Integer
|
318
|
+
|
319
|
+
# See Numeric#divmod.
|
320
|
+
#
|
321
|
+
def divmod: (Integer) -> [Integer, Integer]
|
322
|
+
| (Float) -> [Float, Float]
|
323
|
+
| (Numeric) -> [Numeric, Numeric]
|
324
|
+
|
325
|
+
# Iterates the given block, passing in decreasing values from `int` down to and
|
326
|
+
# including `limit`.
|
327
|
+
#
|
328
|
+
# If no block is given, an Enumerator is returned instead.
|
329
|
+
#
|
330
|
+
# 5.downto(1) { |n| print n, ".. " }
|
331
|
+
# puts "Liftoff!"
|
332
|
+
# #=> "5.. 4.. 3.. 2.. 1.. Liftoff!"
|
333
|
+
#
|
334
|
+
def downto: (Integer limit) { (Integer) -> void } -> Integer
|
335
|
+
| (Integer limit) -> ::Enumerator[Integer, self]
|
336
|
+
|
337
|
+
def dup: () -> self
|
338
|
+
|
339
|
+
def eql?: (untyped) -> bool
|
340
|
+
|
341
|
+
# Returns `true` if `int` is an even number.
|
342
|
+
#
|
343
|
+
def even?: () -> bool
|
344
|
+
|
345
|
+
# Returns the floating point result of dividing `int` by `numeric`.
|
346
|
+
#
|
347
|
+
# 654321.fdiv(13731) #=> 47.652829364212366
|
348
|
+
# 654321.fdiv(13731.24) #=> 47.65199646936475
|
349
|
+
# -654321.fdiv(13731) #=> -47.652829364212366
|
350
|
+
#
|
351
|
+
def fdiv: (Numeric) -> Float
|
352
|
+
|
353
|
+
def finite?: () -> bool
|
354
|
+
|
355
|
+
# Returns the largest number less than or equal to `int` with a precision of
|
356
|
+
# `ndigits` decimal digits (default: 0).
|
357
|
+
#
|
358
|
+
# When the precision is negative, the returned value is an integer with at least
|
359
|
+
# `ndigits.abs` trailing zeros.
|
360
|
+
#
|
361
|
+
# Returns `self` when `ndigits` is zero or positive.
|
362
|
+
#
|
363
|
+
# 1.floor #=> 1
|
364
|
+
# 1.floor(2) #=> 1
|
365
|
+
# 18.floor(-1) #=> 10
|
366
|
+
# (-18).floor(-1) #=> -20
|
367
|
+
#
|
368
|
+
def floor: () -> Integer
|
369
|
+
| (int digits) -> (Integer | Float)
|
370
|
+
|
371
|
+
# Returns the greatest common divisor of the two integers. The result is always
|
372
|
+
# positive. 0.gcd(x) and x.gcd(0) return x.abs.
|
373
|
+
#
|
374
|
+
# 36.gcd(60) #=> 12
|
375
|
+
# 2.gcd(2) #=> 2
|
376
|
+
# 3.gcd(-7) #=> 1
|
377
|
+
# ((1<<31)-1).gcd((1<<61)-1) #=> 1
|
378
|
+
#
|
379
|
+
def gcd: (Integer) -> Integer
|
380
|
+
|
381
|
+
# Returns an array with the greatest common divisor and the least common
|
382
|
+
# multiple of the two integers, [gcd, lcm].
|
383
|
+
#
|
384
|
+
# 36.gcdlcm(60) #=> [12, 180]
|
385
|
+
# 2.gcdlcm(2) #=> [2, 2]
|
386
|
+
# 3.gcdlcm(-7) #=> [1, 21]
|
387
|
+
# ((1<<31)-1).gcdlcm((1<<61)-1) #=> [1, 4951760154835678088235319297]
|
388
|
+
#
|
389
|
+
def gcdlcm: (Integer) -> [ Integer, Integer ]
|
390
|
+
|
391
|
+
def i: () -> Complex
|
392
|
+
|
393
|
+
def imag: () -> Integer
|
394
|
+
|
395
|
+
def imaginary: () -> Integer
|
396
|
+
|
397
|
+
def infinite?: () -> Integer?
|
398
|
+
|
399
|
+
alias inspect to_s
|
400
|
+
|
401
|
+
# Since `int` is already an Integer, this always returns `true`.
|
402
|
+
#
|
403
|
+
def integer?: () -> true
|
404
|
+
|
405
|
+
# Returns the least common multiple of the two integers. The result is always
|
406
|
+
# positive. 0.lcm(x) and x.lcm(0) return zero.
|
407
|
+
#
|
408
|
+
# 36.lcm(60) #=> 180
|
409
|
+
# 2.lcm(2) #=> 2
|
410
|
+
# 3.lcm(-7) #=> 21
|
411
|
+
# ((1<<31)-1).lcm((1<<61)-1) #=> 4951760154835678088235319297
|
412
|
+
#
|
413
|
+
def lcm: (Integer) -> Integer
|
414
|
+
|
415
|
+
# Returns the absolute value of `int`.
|
416
|
+
#
|
417
|
+
# (-12345).abs #=> 12345
|
418
|
+
# -12345.abs #=> 12345
|
419
|
+
# 12345.abs #=> 12345
|
420
|
+
#
|
421
|
+
# Integer#magnitude is an alias for Integer#abs.
|
422
|
+
#
|
423
|
+
def magnitude: () -> Integer
|
424
|
+
|
425
|
+
# Returns `int` modulo `other`.
|
426
|
+
#
|
427
|
+
# See Numeric#divmod for more information.
|
428
|
+
#
|
429
|
+
alias modulo `%`
|
430
|
+
|
431
|
+
def negative?: () -> bool
|
432
|
+
|
433
|
+
# Returns the successor of `int`, i.e. the Integer equal to `int+1`.
|
434
|
+
#
|
435
|
+
# 1.next #=> 2
|
436
|
+
# (-1).next #=> 0
|
437
|
+
# 1.succ #=> 2
|
438
|
+
# (-1).succ #=> 0
|
439
|
+
#
|
440
|
+
def next: () -> Integer
|
441
|
+
|
442
|
+
# Returns `true` if no bits of `int & mask` are 1.
|
443
|
+
#
|
444
|
+
def nobits?: (int mask) -> bool
|
445
|
+
|
446
|
+
def nonzero?: () -> self?
|
447
|
+
|
448
|
+
# Returns self.
|
449
|
+
#
|
450
|
+
def numerator: () -> Integer
|
451
|
+
|
452
|
+
# Returns `true` if `int` is an odd number.
|
453
|
+
#
|
454
|
+
def odd?: () -> bool
|
455
|
+
|
456
|
+
# Returns the `int` itself.
|
457
|
+
#
|
458
|
+
# 97.ord #=> 97
|
459
|
+
#
|
460
|
+
# This method is intended for compatibility to character literals in Ruby 1.9.
|
461
|
+
#
|
462
|
+
# For example, `?a.ord` returns 97 both in 1.8 and 1.9.
|
463
|
+
#
|
464
|
+
def ord: () -> Integer
|
465
|
+
|
466
|
+
alias phase angle
|
467
|
+
|
468
|
+
def polar: () -> [ Integer, Integer | Float ]
|
469
|
+
|
470
|
+
def positive?: () -> bool
|
471
|
+
|
472
|
+
# Returns (modular) exponentiation as:
|
473
|
+
#
|
474
|
+
# a.pow(b) #=> same as a**b
|
475
|
+
# a.pow(b, m) #=> same as (a**b) % m, but avoids huge temporary values
|
476
|
+
#
|
477
|
+
def pow: (Integer other, ?Integer modulo) -> Integer
|
478
|
+
| (Numeric numeric) -> Numeric
|
479
|
+
|
480
|
+
# Returns the predecessor of `int`, i.e. the Integer equal to `int-1`.
|
481
|
+
#
|
482
|
+
# 1.pred #=> 0
|
483
|
+
# (-1).pred #=> -2
|
484
|
+
#
|
485
|
+
def pred: () -> Integer
|
486
|
+
|
487
|
+
def quo: (Integer) -> Rational
|
488
|
+
| (Float) -> Float
|
489
|
+
| (Rational) -> Rational
|
490
|
+
| (Complex) -> Complex
|
491
|
+
| (Numeric) -> Numeric
|
492
|
+
|
493
|
+
# Returns the value as a rational. The optional argument `eps` is always
|
494
|
+
# ignored.
|
495
|
+
#
|
496
|
+
def rationalize: (?Numeric eps) -> Rational
|
497
|
+
|
498
|
+
def real: () -> self
|
499
|
+
|
500
|
+
def real?: () -> true
|
501
|
+
|
502
|
+
def rect: () -> [ Integer, Numeric ]
|
503
|
+
|
504
|
+
alias rectangular rect
|
505
|
+
|
506
|
+
# Returns the remainder after dividing `int` by `numeric`.
|
507
|
+
#
|
508
|
+
# `x.remainder(y)` means `x-y*(x/y).truncate`.
|
509
|
+
#
|
510
|
+
# 5.remainder(3) #=> 2
|
511
|
+
# -5.remainder(3) #=> -2
|
512
|
+
# 5.remainder(-3) #=> 2
|
513
|
+
# -5.remainder(-3) #=> -2
|
514
|
+
# 5.remainder(1.5) #=> 0.5
|
515
|
+
#
|
516
|
+
# See Numeric#divmod.
|
517
|
+
#
|
518
|
+
def remainder: (Integer) -> Integer
|
519
|
+
| (Float) -> Float
|
520
|
+
| (Rational) -> Rational
|
521
|
+
| (Numeric) -> Numeric
|
522
|
+
|
523
|
+
# Returns `int` rounded to the nearest value with a precision of `ndigits`
|
524
|
+
# decimal digits (default: 0).
|
525
|
+
#
|
526
|
+
# When the precision is negative, the returned value is an integer with at least
|
527
|
+
# `ndigits.abs` trailing zeros.
|
528
|
+
#
|
529
|
+
# Returns `self` when `ndigits` is zero or positive.
|
530
|
+
#
|
531
|
+
# 1.round #=> 1
|
532
|
+
# 1.round(2) #=> 1
|
533
|
+
# 15.round(-1) #=> 20
|
534
|
+
# (-15).round(-1) #=> -20
|
535
|
+
#
|
536
|
+
# The optional `half` keyword argument is available similar to Float#round.
|
537
|
+
#
|
538
|
+
# 25.round(-1, half: :up) #=> 30
|
539
|
+
# 25.round(-1, half: :down) #=> 20
|
540
|
+
# 25.round(-1, half: :even) #=> 20
|
541
|
+
# 35.round(-1, half: :up) #=> 40
|
542
|
+
# 35.round(-1, half: :down) #=> 30
|
543
|
+
# 35.round(-1, half: :even) #=> 40
|
544
|
+
# (-25).round(-1, half: :up) #=> -30
|
545
|
+
# (-25).round(-1, half: :down) #=> -20
|
546
|
+
# (-25).round(-1, half: :even) #=> -20
|
547
|
+
#
|
548
|
+
def round: (?half: :up | :down | :even) -> Integer
|
549
|
+
| (int digits, ?half: :up | :down | :even) -> (Integer | Float)
|
550
|
+
|
551
|
+
# Returns the number of bytes in the machine representation of `int` (machine
|
552
|
+
# dependent).
|
553
|
+
#
|
554
|
+
# 1.size #=> 8
|
555
|
+
# -1.size #=> 8
|
556
|
+
# 2147483647.size #=> 8
|
557
|
+
# (256**10 - 1).size #=> 10
|
558
|
+
# (256**20 - 1).size #=> 20
|
559
|
+
# (256**40 - 1).size #=> 40
|
560
|
+
#
|
561
|
+
def size: () -> Integer
|
562
|
+
|
563
|
+
def step: () { (Integer) -> void } -> void
|
564
|
+
| (Numeric limit, ?Integer step) { (Integer) -> void } -> void
|
565
|
+
| (Numeric limit, ?Numeric step) { (Numeric) -> void } -> void
|
566
|
+
| (to: Numeric, ?by: Integer) { (Integer) -> void } -> void
|
567
|
+
| (?to: Numeric, by: Numeric) { (Numeric) -> void } -> void
|
568
|
+
| () -> Enumerator[Integer, bot]
|
569
|
+
| (Numeric limit, ?Integer step) -> Enumerator[Integer, void]
|
570
|
+
| (Numeric limit, ?Numeric step) -> Enumerator[Numeric, void]
|
571
|
+
| (to: Numeric, ?by: Integer) -> Enumerator[Integer, void]
|
572
|
+
| (?to: Numeric, by: Numeric) -> Enumerator[Numeric, void]
|
573
|
+
|
574
|
+
# Returns the successor of `int`, i.e. the Integer equal to `int+1`.
|
575
|
+
#
|
576
|
+
# 1.next #=> 2
|
577
|
+
# (-1).next #=> 0
|
578
|
+
# 1.succ #=> 2
|
579
|
+
# (-1).succ #=> 0
|
580
|
+
#
|
581
|
+
def succ: () -> Integer
|
582
|
+
|
583
|
+
# Iterates the given block `int` times, passing in values from zero to `int -
|
584
|
+
# 1`.
|
585
|
+
#
|
586
|
+
# If no block is given, an Enumerator is returned instead.
|
587
|
+
#
|
588
|
+
# 5.times {|i| print i, " " } #=> 0 1 2 3 4
|
589
|
+
#
|
590
|
+
def times: () { (Integer) -> void } -> self
|
591
|
+
| () -> ::Enumerator[Integer, self]
|
592
|
+
|
593
|
+
def to_c: () -> Complex
|
594
|
+
|
595
|
+
# Converts `int` to a Float. If `int` doesn't fit in a Float, the result is
|
596
|
+
# infinity.
|
597
|
+
#
|
598
|
+
def to_f: () -> Float
|
599
|
+
|
600
|
+
# Since `int` is already an Integer, returns `self`.
|
601
|
+
#
|
602
|
+
# #to_int is an alias for #to_i.
|
603
|
+
#
|
604
|
+
def to_i: () -> Integer
|
605
|
+
|
606
|
+
# Since `int` is already an Integer, returns `self`.
|
607
|
+
#
|
608
|
+
# #to_int is an alias for #to_i.
|
609
|
+
#
|
610
|
+
alias to_int to_i
|
611
|
+
|
612
|
+
# Returns the value as a rational.
|
613
|
+
#
|
614
|
+
# 1.to_r #=> (1/1)
|
615
|
+
# (1<<64).to_r #=> (18446744073709551616/1)
|
616
|
+
#
|
617
|
+
def to_r: () -> Rational
|
618
|
+
|
619
|
+
# Returns a string containing the place-value representation of `int` with radix
|
620
|
+
# `base` (between 2 and 36).
|
621
|
+
#
|
622
|
+
# 12345.to_s #=> "12345"
|
623
|
+
# 12345.to_s(2) #=> "11000000111001"
|
624
|
+
# 12345.to_s(8) #=> "30071"
|
625
|
+
# 12345.to_s(10) #=> "12345"
|
626
|
+
# 12345.to_s(16) #=> "3039"
|
627
|
+
# 12345.to_s(36) #=> "9ix"
|
628
|
+
# 78546939656932.to_s(36) #=> "rubyrules"
|
629
|
+
#
|
630
|
+
def to_s: () -> String
|
631
|
+
| (2) -> String
|
632
|
+
| (3) -> String
|
633
|
+
| (4) -> String
|
634
|
+
| (5) -> String
|
635
|
+
| (6) -> String
|
636
|
+
| (7) -> String
|
637
|
+
| (8) -> String
|
638
|
+
| (9) -> String
|
639
|
+
| (10) -> String
|
640
|
+
| (11) -> String
|
641
|
+
| (12) -> String
|
642
|
+
| (13) -> String
|
643
|
+
| (14) -> String
|
644
|
+
| (15) -> String
|
645
|
+
| (16) -> String
|
646
|
+
| (17) -> String
|
647
|
+
| (18) -> String
|
648
|
+
| (19) -> String
|
649
|
+
| (20) -> String
|
650
|
+
| (21) -> String
|
651
|
+
| (22) -> String
|
652
|
+
| (23) -> String
|
653
|
+
| (24) -> String
|
654
|
+
| (25) -> String
|
655
|
+
| (26) -> String
|
656
|
+
| (27) -> String
|
657
|
+
| (28) -> String
|
658
|
+
| (29) -> String
|
659
|
+
| (30) -> String
|
660
|
+
| (31) -> String
|
661
|
+
| (32) -> String
|
662
|
+
| (33) -> String
|
663
|
+
| (34) -> String
|
664
|
+
| (35) -> String
|
665
|
+
| (36) -> String
|
666
|
+
| (int base) -> String
|
667
|
+
|
668
|
+
# Returns `int` truncated (toward zero) to a precision of `ndigits` decimal
|
669
|
+
# digits (default: 0).
|
670
|
+
#
|
671
|
+
# When the precision is negative, the returned value is an integer with at least
|
672
|
+
# `ndigits.abs` trailing zeros.
|
673
|
+
#
|
674
|
+
# Returns `self` when `ndigits` is zero or positive.
|
675
|
+
#
|
676
|
+
# 1.truncate #=> 1
|
677
|
+
# 1.truncate(2) #=> 1
|
678
|
+
# 18.truncate(-1) #=> 10
|
679
|
+
# (-18).truncate(-1) #=> -10
|
680
|
+
#
|
681
|
+
def truncate: () -> Integer
|
682
|
+
| (int ndigits) -> Integer
|
683
|
+
|
684
|
+
# Iterates the given block, passing in integer values from `int` up to and
|
685
|
+
# including `limit`.
|
686
|
+
#
|
687
|
+
# If no block is given, an Enumerator is returned instead.
|
688
|
+
#
|
689
|
+
# 5.upto(10) {|i| print i, " " } #=> 5 6 7 8 9 10
|
690
|
+
#
|
691
|
+
def upto: (Integer limit) { (Integer) -> void } -> Integer
|
692
|
+
| (Integer limit) -> ::Enumerator[Integer, self]
|
693
|
+
|
694
|
+
def zero?: () -> bool
|
695
|
+
|
696
|
+
# Bitwise OR.
|
697
|
+
#
|
698
|
+
def |: (Integer) -> Integer
|
699
|
+
|
700
|
+
# One's complement: returns a number where each bit is flipped.
|
701
|
+
#
|
702
|
+
# Inverts the bits in an Integer. As integers are conceptually of infinite
|
703
|
+
# length, the result acts as if it had an infinite number of one bits to the
|
704
|
+
# left. In hex representations, this is displayed as two periods to the left of
|
705
|
+
# the digits.
|
706
|
+
#
|
707
|
+
# sprintf("%X", ~0x1122334455) #=> "..FEEDDCCBBAA"
|
708
|
+
#
|
709
|
+
def ~: () -> Integer
|
710
|
+
end
|