steep 0.13.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +28 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep.rb +33 -1
  9. data/lib/steep/annotation_parser.rb +4 -4
  10. data/lib/steep/ast/buffer.rb +11 -7
  11. data/lib/steep/ast/builtin.rb +8 -0
  12. data/lib/steep/ast/types/factory.rb +124 -89
  13. data/lib/steep/cli.rb +16 -1
  14. data/lib/steep/drivers/annotations.rb +1 -1
  15. data/lib/steep/drivers/check.rb +20 -4
  16. data/lib/steep/drivers/init.rb +5 -5
  17. data/lib/steep/drivers/langserver.rb +13 -287
  18. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  19. data/lib/steep/drivers/vendor.rb +2 -2
  20. data/lib/steep/drivers/watch.rb +97 -85
  21. data/lib/steep/drivers/worker.rb +51 -0
  22. data/lib/steep/project.rb +9 -5
  23. data/lib/steep/project/completion_provider.rb +298 -0
  24. data/lib/steep/project/dsl.rb +14 -0
  25. data/lib/steep/project/file.rb +54 -47
  26. data/lib/steep/project/hover_content.rb +17 -8
  27. data/lib/steep/project/options.rb +25 -3
  28. data/lib/steep/project/target.rb +40 -24
  29. data/lib/steep/server/base_worker.rb +56 -0
  30. data/lib/steep/server/code_worker.rb +151 -0
  31. data/lib/steep/server/interaction_worker.rb +281 -0
  32. data/lib/steep/server/master.rb +196 -0
  33. data/lib/steep/server/signature_worker.rb +148 -0
  34. data/lib/steep/server/utils.rb +36 -0
  35. data/lib/steep/server/worker_process.rb +62 -0
  36. data/lib/steep/signature/errors.rb +1 -1
  37. data/lib/steep/signature/validator.rb +13 -13
  38. data/lib/steep/source.rb +1 -1
  39. data/lib/steep/type_construction.rb +1004 -727
  40. data/lib/steep/type_inference/constant_env.rb +3 -11
  41. data/lib/steep/type_inference/context.rb +8 -3
  42. data/lib/steep/type_inference/context_array.rb +111 -0
  43. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  44. data/lib/steep/type_inference/logic.rb +130 -0
  45. data/lib/steep/type_inference/type_env.rb +5 -69
  46. data/lib/steep/typing.rb +91 -23
  47. data/lib/steep/version.rb +1 -1
  48. data/smoke/alias/Steepfile +1 -0
  49. data/smoke/alias/a.rb +1 -1
  50. data/smoke/and/Steepfile +1 -0
  51. data/smoke/array/Steepfile +1 -0
  52. data/smoke/array/b.rb +0 -2
  53. data/smoke/block/Steepfile +1 -0
  54. data/smoke/case/Steepfile +1 -0
  55. data/smoke/class/Steepfile +1 -0
  56. data/smoke/const/Steepfile +1 -0
  57. data/smoke/dstr/Steepfile +1 -0
  58. data/smoke/ensure/Steepfile +1 -0
  59. data/smoke/enumerator/Steepfile +1 -0
  60. data/smoke/extension/Steepfile +1 -0
  61. data/smoke/extension/c.rb +1 -0
  62. data/smoke/hash/Steepfile +1 -0
  63. data/smoke/hello/Steepfile +1 -0
  64. data/smoke/if/Steepfile +1 -0
  65. data/smoke/if/a.rb +1 -1
  66. data/smoke/implements/Steepfile +1 -0
  67. data/smoke/initialize/Steepfile +1 -0
  68. data/smoke/integer/Steepfile +1 -0
  69. data/smoke/interface/Steepfile +1 -0
  70. data/smoke/kwbegin/Steepfile +1 -0
  71. data/smoke/lambda/Steepfile +1 -0
  72. data/smoke/literal/Steepfile +1 -0
  73. data/smoke/map/Steepfile +1 -0
  74. data/smoke/method/Steepfile +1 -0
  75. data/smoke/module/Steepfile +1 -0
  76. data/smoke/regexp/Steepfile +1 -0
  77. data/smoke/regexp/b.rb +4 -4
  78. data/smoke/regression/Steepfile +1 -0
  79. data/smoke/rescue/Steepfile +1 -0
  80. data/smoke/rescue/a.rb +1 -1
  81. data/smoke/self/Steepfile +1 -0
  82. data/smoke/skip/Steepfile +1 -0
  83. data/smoke/stdout/Steepfile +1 -0
  84. data/smoke/super/Steepfile +1 -0
  85. data/smoke/type_case/Steepfile +1 -0
  86. data/smoke/yield/Steepfile +1 -0
  87. data/steep.gemspec +8 -8
  88. metadata +38 -138
  89. data/exe/rbs +0 -3
  90. data/exe/ruby-signature +0 -3
  91. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  92. data/vendor/ruby-signature/.gitignore +0 -12
  93. data/vendor/ruby-signature/.rubocop.yml +0 -15
  94. data/vendor/ruby-signature/BSDL +0 -22
  95. data/vendor/ruby-signature/COPYING +0 -56
  96. data/vendor/ruby-signature/Gemfile +0 -6
  97. data/vendor/ruby-signature/README.md +0 -93
  98. data/vendor/ruby-signature/Rakefile +0 -66
  99. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
  100. data/vendor/ruby-signature/bin/console +0 -14
  101. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  102. data/vendor/ruby-signature/bin/setup +0 -10
  103. data/vendor/ruby-signature/bin/sort +0 -88
  104. data/vendor/ruby-signature/bin/test_runner.rb +0 -17
  105. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  106. data/vendor/ruby-signature/docs/sigs.md +0 -148
  107. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  108. data/vendor/ruby-signature/docs/syntax.md +0 -528
  109. data/vendor/ruby-signature/exe/rbs +0 -3
  110. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  111. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
  112. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  113. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  114. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  115. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  116. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  117. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  118. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
  119. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  120. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  121. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  122. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  123. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  124. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  125. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  126. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  127. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  128. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  129. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  130. data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
  131. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
  132. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  133. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  134. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  135. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  136. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  137. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  138. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
  139. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
  140. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  141. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  142. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  143. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  144. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  145. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  146. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  147. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
  148. data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
  149. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
  150. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
  151. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  152. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  153. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  154. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
  155. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  156. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  157. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  158. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  159. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  160. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  161. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
  162. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
  163. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  164. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  165. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  166. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  167. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
  168. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  169. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  170. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  171. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
  172. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  173. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  174. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
  175. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  176. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
  177. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  178. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
  179. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
  180. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
  181. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
  182. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
  183. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
  184. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  185. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  186. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  187. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
  188. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
  189. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
  190. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  191. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  192. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
  193. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
  194. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  195. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  196. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
  197. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
  198. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  199. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
  200. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
  201. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  202. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
  203. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
  204. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  205. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
  206. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  207. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
  208. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
  209. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
  210. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  211. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  212. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  213. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
  214. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,10 +0,0 @@
1
- module RbConfig
2
- end
3
-
4
- RbConfig::CONFIG: Hash[String, String]
5
-
6
- RbConfig::DESTDIR: String
7
-
8
- RbConfig::MAKEFILE_CONFIG: Hash[String, String]
9
-
10
- RbConfig::TOPDIR: String
@@ -1,131 +0,0 @@
1
- class Regexp < Object
2
- def self.escape: (String | Symbol arg0) -> String
3
-
4
- def self.last_match: () -> MatchData?
5
- | (Integer n) -> String?
6
- | (Symbol | String n) -> String?
7
-
8
- def self.try_convert: (untyped obj) -> Regexp?
9
-
10
- def ==: (untyped other) -> bool
11
-
12
- def ===: (untyped other) -> bool
13
-
14
- def =~: (String? str) -> Integer?
15
-
16
- # Returns the value of the case-insensitive flag.
17
- #
18
- # ```ruby
19
- # /a/.casefold? #=> false
20
- # /a/i.casefold? #=> true
21
- # /(?i:a)/.casefold? #=> false
22
- # ```
23
- def casefold?: () -> bool
24
-
25
- # Returns the [Encoding](https://ruby-doc.org/core-2.6.3/Encoding.html)
26
- # object that represents the encoding of obj.
27
- def encoding: () -> Encoding
28
-
29
- def fixed_encoding?: () -> bool
30
-
31
- # Produce a hash based on the text and options of this regular expression.
32
- #
33
- # See also Object\#hash.
34
- def hash: () -> Integer
35
-
36
- def initialize: (String arg0, ?untyped options, ?String kcode) -> Object
37
- | (Regexp arg0) -> void
38
-
39
- # Produce a nicely formatted string-version of *rxp* . Perhaps
40
- # surprisingly, `#inspect` actually produces the more natural version of
41
- # the string than `#to_s` .
42
- #
43
- # ```ruby
44
- # /ab+c/ix.inspect #=> "/ab+c/ix"
45
- # ```
46
- def inspect: () -> String
47
-
48
- def match: (String? | Symbol | _ToStr arg0, ?Integer arg1) -> MatchData?
49
- | (String? | Symbol | _ToStr arg0, ?Integer arg1) { (MatchData) -> untyped } -> untyped
50
-
51
- def match?: (String? | Symbol | _ToStr arg0, ?Integer arg1) -> bool
52
-
53
- def named_captures: () -> ::Hash[String, ::Array[Integer]]
54
-
55
- def names: () -> ::Array[String]
56
-
57
- # Returns the set of bits corresponding to the options used when creating
58
- # this [Regexp](Regexp.downloaded.ruby_doc) (see `Regexp::new` for
59
- # details. Note that additional bits may be set in the returned options:
60
- # these are used internally by the regular expression code. These extra
61
- # bits are ignored if the options are passed to `Regexp::new` .
62
- #
63
- # ```ruby
64
- # Regexp::IGNORECASE #=> 1
65
- # Regexp::EXTENDED #=> 2
66
- # Regexp::MULTILINE #=> 4
67
- #
68
- # /cat/.options #=> 0
69
- # /cat/ix.options #=> 3
70
- # Regexp.new('cat', true).options #=> 1
71
- # /\xa1\xa2/e.options #=> 16
72
- #
73
- # r = /cat/ix
74
- # Regexp.new(r.source, r.options) #=> /cat/ix
75
- # ```
76
- def options: () -> Integer
77
-
78
- # Returns the original string of the pattern.
79
- #
80
- # ```ruby
81
- # /ab+c/ix.source #=> "ab+c"
82
- # ```
83
- #
84
- # Note that escape sequences are retained as is.
85
- #
86
- # ```ruby
87
- # /\x20\+/.source #=> "\\x20\\+"
88
- # ```
89
- def source: () -> String
90
-
91
- # Returns a string containing the regular expression and its options
92
- # (using the `(?opts:source)` notation. This string can be fed back in to
93
- # `Regexp::new` to a regular expression with the same semantics as the
94
- # original. (However, `Regexp#==` may not return true when comparing the
95
- # two, as the source of the regular expression itself may differ, as the
96
- # example shows). `Regexp#inspect` produces a generally more readable
97
- # version of *rxp* .
98
- #
99
- # ```ruby
100
- # r1 = /ab+c/ix #=> /ab+c/ix
101
- # s1 = r1.to_s #=> "(?ix-m:ab+c)"
102
- # r2 = Regexp.new(s1) #=> /(?ix-m:ab+c)/
103
- # r1 == r2 #=> false
104
- # r1.source #=> "ab+c"
105
- # r2.source #=> "(?ix-m:ab+c)"
106
- # ```
107
- def to_s: () -> String
108
-
109
- def ~: () -> Integer?
110
-
111
- def self.compile: (String arg0, ?untyped options, ?String kcode) -> Regexp
112
- | (Regexp arg0) -> Regexp
113
-
114
- def self.quote: (String | Symbol arg0) -> String
115
-
116
- def self.union: () -> Regexp
117
- | (String | Regexp arg0, *String | Regexp args) -> Regexp
118
- | (::Array[String | Regexp]) -> Regexp
119
-
120
- def eql?: (untyped other) -> bool
121
- end
122
-
123
- Regexp::EXTENDED: Integer
124
-
125
- Regexp::FIXEDENCODING: Integer
126
-
127
- Regexp::IGNORECASE: Integer
128
-
129
- Regexp::MULTILINE: Integer
130
-
131
- Regexp::NOENCODING: Integer
@@ -1,14 +0,0 @@
1
- # The [RubyVM](RubyVM) module provides some access to
2
- # Ruby internals. This module is for very limited purposes, such as
3
- # debugging, prototyping, and research. Normal users must not use it.
4
- class RubyVM < Object
5
- end
6
-
7
- RubyVM::DEFAULT_PARAMS: Hash[Symbol, Integer]
8
-
9
- RubyVM::INSTRUCTION_NAMES: Array[String]
10
-
11
- RubyVM::OPTS: Array[String]
12
-
13
- class RubyVM::InstructionSequence < Object
14
- end
@@ -1,55 +0,0 @@
1
- # Many operating systems allow signals to be sent to running processes.
2
- # Some signals have a defined effect on the process, while others may be
3
- # trapped at the code level and acted upon. For example, your process may
4
- # trap the USR1 signal and use it to toggle debugging, and may use TERM to
5
- # initiate a controlled shutdown.
6
- #
7
- # ```ruby
8
- # pid = fork do
9
- # Signal.trap("USR1") do
10
- # $debug = !$debug
11
- # puts "Debug now: #$debug"
12
- # end
13
- # Signal.trap("TERM") do
14
- # puts "Terminating..."
15
- # shutdown()
16
- # end
17
- # # . . . do some work . . .
18
- # end
19
- #
20
- # Process.detach(pid)
21
- #
22
- # # Controlling program:
23
- # Process.kill("USR1", pid)
24
- # # ...
25
- # Process.kill("USR1", pid)
26
- # # ...
27
- # Process.kill("TERM", pid)
28
- # ```
29
- #
30
- # produces:
31
- #
32
- # ```
33
- # Debug now: true
34
- # Debug now: false
35
- # Terminating...
36
- # ```
37
- #
38
- # The list of available signal names and their interpretation is system
39
- # dependent. [Signal](Signal) delivery semantics may
40
- # also vary between systems; in particular signal delivery may not always
41
- # be reliable.
42
- module Signal
43
- # Returns a list of signal names mapped to the corresponding underlying
44
- # signal numbers.
45
- #
46
- # ```ruby
47
- # Signal.list #=> {"EXIT"=>0, "HUP"=>1, "INT"=>2, "QUIT"=>3, "ILL"=>4, "TRAP"=>5, "IOT"=>6, "ABRT"=>6, "FPE"=>8, "KILL"=>9, "BUS"=>7, "SEGV"=>11, "SYS"=>31, "PIPE"=>13, "ALRM"=>14, "TERM"=>15, "URG"=>23, "STOP"=>19, "TSTP"=>20, "CONT"=>18, "CHLD"=>17, "CLD"=>17, "TTIN"=>21, "TTOU"=>22, "IO"=>29, "XCPU"=>24, "XFSZ"=>25, "VTALRM"=>26, "PROF"=>27, "WINCH"=>28, "USR1"=>10, "USR2"=>12, "PWR"=>30, "POLL"=>29}
48
- # ```
49
- def self.list: () -> ::Hash[String, Integer]
50
-
51
- def self.signame: (Integer arg0) -> String?
52
-
53
- def self.trap: (Integer | String | Symbol signal, ?untyped command) -> (String | Proc)
54
- | (Integer | String | Symbol signal) { (Integer arg0) -> untyped } -> (String | Proc)
55
- end
@@ -1,770 +0,0 @@
1
- # A `String` object holds and manipulates an arbitrary sequence of bytes,
2
- # typically representing characters. [String](String)
3
- # objects may be created using `String::new` or as literals.
4
- #
5
- # Because of aliasing issues, users of strings should be aware of the
6
- # methods that modify the contents of a `String` object. Typically,
7
- # methods with names ending in “\!” modify their receiver, while those
8
- # without a “\!” return a new `String` . However, there are exceptions,
9
- # such as `String#[]=` .
10
- class String < Object
11
- include Comparable
12
-
13
- def %: (Object arg0) -> String
14
-
15
- def *: (Integer arg0) -> String
16
-
17
- def +: (String arg0) -> String
18
-
19
- def <<: (Object arg0) -> String
20
-
21
- def <=>: (String other) -> Integer?
22
-
23
- def ==: (untyped arg0) -> bool
24
-
25
- def ===: (untyped arg0) -> bool
26
-
27
- %a{rbs:test:skip}
28
- def =~: (Object arg0) -> Integer?
29
-
30
- def []: (Integer arg0, ?Integer arg1) -> String?
31
- | (::Range[Integer] | Regexp arg0) -> String?
32
- | (Regexp arg0, ?Integer arg1) -> String?
33
- | (Regexp arg0, ?String arg1) -> String?
34
- | (String arg0) -> String?
35
-
36
- # Returns true for a string which has only ASCII characters.
37
- #
38
- # ```ruby
39
- # "abc".force_encoding("UTF-8").ascii_only? #=> true
40
- # "abc\u{6666}".force_encoding("UTF-8").ascii_only? #=> false
41
- # ```
42
- def ascii_only?: () -> bool
43
-
44
- # Returns a copied string whose encoding is ASCII-8BIT.
45
- def b: () -> String
46
-
47
- # Returns an array of bytes in *str* . This is a shorthand for
48
- # `str.each_byte.to_a` .
49
- #
50
- # If a block is given, which is a deprecated form, works the same as
51
- # `each_byte` .
52
- def bytes: () -> Array[String]
53
-
54
- # Returns the length of `str` in bytes.
55
- #
56
- # "\x80\u3042".bytesize #=> 4
57
- # "hello".bytesize #=> 5
58
- def bytesize: () -> Integer
59
-
60
- def byteslice: (Integer arg0, ?Integer arg1) -> String?
61
- | (::Range[Integer] arg0) -> String?
62
-
63
- # Returns a copy of *str* with the first character converted to uppercase
64
- # and the remainder to lowercase.
65
- #
66
- # See [\#downcase](String.downloaded.ruby_doc#method-i-downcase) for
67
- # meaning of `options` and use with different encodings.
68
- #
69
- # ```ruby
70
- # "hello".capitalize #=> "Hello"
71
- # "HELLO".capitalize #=> "Hello"
72
- # "123ABC".capitalize #=> "123abc"
73
- # ```
74
- def capitalize: () -> String
75
-
76
- # Modifies *str* by converting the first character to uppercase and the
77
- # remainder to lowercase. Returns `nil` if no changes are made. There is
78
- # an exception for modern Georgian (mkhedruli/MTAVRULI), where the result
79
- # is the same as for
80
- # [\#downcase](String.downloaded.ruby_doc#method-i-downcase), to avoid
81
- # mixed case.
82
- #
83
- # See [\#downcase](String.downloaded.ruby_doc#method-i-downcase) for
84
- # meaning of `options` and use with different encodings.
85
- #
86
- # ```ruby
87
- # a = "hello"
88
- # a.capitalize! #=> "Hello"
89
- # a #=> "Hello"
90
- # a.capitalize! #=> nil
91
- # ```
92
- def capitalize!: () -> String?
93
-
94
- def casecmp: (String arg0) -> Integer?
95
-
96
- def center: (Integer arg0, ?String arg1) -> String
97
-
98
- # Returns an array of characters in *str* . This is a shorthand for
99
- # `str.each_char.to_a` .
100
- #
101
- # If a block is given, which is a deprecated form, works the same as
102
- # `each_char` .
103
- def chars: () -> Array[String]
104
-
105
- def chomp: (?String arg0) -> String
106
-
107
- def chomp!: (?String arg0) -> String?
108
-
109
- # Returns a new `String` with the last character removed. If the string
110
- # ends with `\r\n`, both characters are removed. Applying `chop` to an
111
- # empty string returns an empty string. `String#chomp` is often a safer
112
- # alternative, as it leaves the string unchanged if it doesn’t end in a
113
- # record separator.
114
- #
115
- # ```ruby
116
- # "string\r\n".chop #=> "string"
117
- # "string\n\r".chop #=> "string\n"
118
- # "string\n".chop #=> "string"
119
- # "string".chop #=> "strin"
120
- # "x".chop.chop #=> ""
121
- # ```
122
- def chop: () -> String
123
-
124
- # Processes *str* as for `String#chop`, returning *str* , or `nil` if
125
- # *str* is the empty string. See also `String#chomp!` .
126
- def chop!: () -> String?
127
-
128
- # Returns a one-character string at the beginning of the string.
129
- #
130
- # ```ruby
131
- # a = "abcde"
132
- # a.chr #=> "a"
133
- # ```
134
- def chr: () -> String
135
-
136
- # Makes string empty.
137
- #
138
- # ```ruby
139
- # a = "abcde"
140
- # a.clear #=> ""
141
- # ```
142
- def clear: () -> String
143
-
144
- # Returns an array of the `Integer` ordinals of the characters in *str* .
145
- # This is a shorthand for `str.each_codepoint.to_a` .
146
- #
147
- # If a block is given, which is a deprecated form, works the same as
148
- # `each_codepoint` .
149
- def codepoints: () -> ::Array[Integer]
150
- | () { () -> untyped } -> ::Array[Integer]
151
-
152
- def concat: (Integer | Object arg0) -> String
153
-
154
- def count: (String arg0, *String arg1) -> Integer
155
-
156
- def crypt: (String arg0) -> String
157
-
158
- def delete: (String arg0, *String arg1) -> String
159
-
160
- def delete!: (String arg0, *String arg1) -> String?
161
-
162
- def delete_prefix: (String) -> String
163
-
164
- def delete_prefix!: (String) -> String?
165
-
166
- def delete_suffix: (String) -> String
167
-
168
- def delete_suffix!: (String) -> String?
169
-
170
- # Returns a copy of *str* with all uppercase letters replaced with their
171
- # lowercase counterparts. Which letters exactly are replaced, and by which
172
- # other letters, depends on the presence or absence of options, and on the
173
- # `encoding` of the string.
174
- #
175
- # The meaning of the `options` is as follows:
176
- #
177
- # - No option
178
- # Full Unicode case mapping, suitable for most languages (see :turkic
179
- # and :lithuanian options below for exceptions). Context-dependent
180
- # case mapping as described in Table 3-14 of the Unicode standard is
181
- # currently not supported.
182
- #
183
- # - :ascii
184
- # Only the ASCII region, i.e. the characters “A” to “Z” and “a” to
185
- # “z”, are affected. This option cannot be combined with any other
186
- # option.
187
- #
188
- # - :turkic
189
- # Full Unicode case mapping, adapted for Turkic languages (Turkish,
190
- # Azerbaijani, …). This means that upper case I is mapped to lower
191
- # case dotless i, and so on.
192
- #
193
- # - :lithuanian
194
- # Currently, just full Unicode case mapping. In the future, full
195
- # Unicode case mapping adapted for Lithuanian (keeping the dot on the
196
- # lower case i even if there is an accent on top).
197
- #
198
- # - :fold
199
- # Only available on `downcase` and `downcase!` . Unicode case
200
- # **folding** , which is more far-reaching than Unicode case mapping.
201
- # This option currently cannot be combined with any other option (i.e.
202
- # there is currently no variant for turkic languages).
203
- #
204
- # Please note that several assumptions that are valid for ASCII-only case
205
- # conversions do not hold for more general case conversions. For example,
206
- # the length of the result may not be the same as the length of the input
207
- # (neither in characters nor in bytes), some roundtrip assumptions (e.g.
208
- # str.downcase == str.upcase.downcase) may not apply, and Unicode
209
- # normalization (i.e.
210
- # [\#unicode\_normalize](String.downloaded.ruby_doc#method-i-unicode_normalize)
211
- # ) is not necessarily maintained by case mapping operations.
212
- #
213
- # Non-ASCII case mapping/folding is currently supported for UTF-8,
214
- # UTF-16BE/LE, UTF-32BE/LE, and ISO-8859-1\~16 Strings/Symbols. This
215
- # support will be extended to other encodings.
216
- #
217
- # ```ruby
218
- # "hEllO".downcase #=> "hello"
219
- # ```
220
- def downcase: () -> String
221
-
222
- # Downcases the contents of *str* , returning `nil` if no changes were
223
- # made.
224
- #
225
- # See [\#downcase](String.downloaded.ruby_doc#method-i-downcase) for
226
- # meaning of `options` and use with different encodings.
227
- def downcase!: () -> String?
228
-
229
- # Produces a version of `str` with all non-printing characters replaced by
230
- # `\nnn` notation and all special characters escaped.
231
- #
232
- # ```ruby
233
- # "hello \n ''".dump #=> "\"hello \\n ''\""
234
- # ```
235
- def dump: () -> String
236
-
237
- def each_byte: () { (Integer arg0) -> untyped } -> String
238
- | () -> ::Enumerator[Integer, self]
239
-
240
- def each_char: () { (String arg0) -> untyped } -> String
241
- | () -> ::Enumerator[String, self]
242
-
243
- def each_codepoint: () { (Integer arg0) -> untyped } -> String
244
- | () -> ::Enumerator[Integer, self]
245
-
246
- def each_line: (?String arg0) { (String arg0) -> untyped } -> String
247
- | (?String arg0) -> ::Enumerator[String, self]
248
-
249
- # Returns `true` if *str* has a length of zero.
250
- #
251
- # ```ruby
252
- # "hello".empty? #=> false
253
- # " ".empty? #=> false
254
- # "".empty? #=> true
255
- # ```
256
- def empty?: () -> bool
257
-
258
- # Returns the [Encoding](https://ruby-doc.org/core-2.6.3/Encoding.html)
259
- # object that represents the encoding of obj.
260
- def encoding: () -> Encoding
261
-
262
- def end_with?: (*String arg0) -> bool
263
-
264
- def eql?: (String arg0) -> bool
265
-
266
- def force_encoding: (String | Encoding arg0) -> String
267
-
268
- def getbyte: (Integer arg0) -> Integer?
269
-
270
- def gsub: (Regexp | String arg0, ?String arg1) -> String
271
- | (Regexp | String arg0, ?Hash[String, String] arg1) -> String
272
- | (Regexp | String arg0) { (String arg0) -> untyped } -> String
273
- | (Regexp | String arg0) -> ::Enumerator[String, self]
274
- | (Regexp | String arg0) -> String
275
-
276
- def gsub!: (Regexp | String arg0, ?String arg1) -> String?
277
- | (Regexp | String arg0) { (String arg0) -> untyped } -> String?
278
- | (Regexp | String arg0) -> ::Enumerator[String, self]
279
-
280
- # Returns a hash based on the string’s length, content and encoding.
281
- #
282
- # See also Object\#hash.
283
- def hash: () -> Integer
284
-
285
- # Treats leading characters from *str* as a string of hexadecimal digits
286
- # (with an optional sign and an optional `0x` ) and returns the
287
- # corresponding number. Zero is returned on error.
288
- #
289
- # ```ruby
290
- # "0x0a".hex #=> 10
291
- # "-1234".hex #=> -4660
292
- # "0".hex #=> 0
293
- # "wombat".hex #=> 0
294
- # ```
295
- def hex: () -> Integer
296
-
297
- def `include?`: (String arg0) -> bool
298
-
299
- def index: (Regexp | String arg0, ?Integer arg1) -> Integer?
300
-
301
- def initialize: (?String str, ?encoding: Encoding | String, ?capacity: Integer) -> void
302
-
303
- def insert: (Integer arg0, String arg1) -> String
304
-
305
- # Returns a printable version of *str* , surrounded by quote marks, with
306
- # special characters escaped.
307
- #
308
- # ```ruby
309
- # str = "hello"
310
- # str[3] = "\b"
311
- # str.inspect #=> "\"hel\\bo\""
312
- # ```
313
- def inspect: () -> String
314
-
315
- # Returns the `Symbol` corresponding to *str* , creating the symbol if it
316
- # did not previously exist. See `Symbol#id2name` .
317
- #
318
- # ```ruby
319
- # "Koala".intern #=> :Koala
320
- # s = 'cat'.to_sym #=> :cat
321
- # s == :cat #=> true
322
- # s = '@cat'.to_sym #=> :@cat
323
- # s == :@cat #=> true
324
- # ```
325
- #
326
- # This can also be used to create symbols that cannot be represented using
327
- # the `:xxx` notation.
328
- #
329
- # ```ruby
330
- # 'cat and dog'.to_sym #=> :"cat and dog"
331
- # ```
332
- def intern: () -> Symbol
333
-
334
- # Returns the character length of *str* .
335
- def length: () -> Integer
336
-
337
- def lines: (?String arg0) -> ::Array[String]
338
-
339
- def ljust: (Integer arg0, ?String arg1) -> String
340
-
341
- # Returns a copy of the receiver with leading whitespace removed. See also
342
- # [\#rstrip](String.downloaded.ruby_doc#method-i-rstrip) and
343
- # [\#strip](String.downloaded.ruby_doc#method-i-strip).
344
- #
345
- # Refer to [\#strip](String.downloaded.ruby_doc#method-i-strip) for the
346
- # definition of whitespace.
347
- #
348
- # ```ruby
349
- # " hello ".lstrip #=> "hello "
350
- # "hello".lstrip #=> "hello"
351
- # ```
352
- def lstrip: () -> String
353
-
354
- # Removes leading whitespace from the receiver. Returns the altered
355
- # receiver, or `nil` if no change was made. See also
356
- # [\#rstrip\!](String.downloaded.ruby_doc#method-i-rstrip-21) and
357
- # [\#strip\!](String.downloaded.ruby_doc#method-i-strip-21).
358
- #
359
- # Refer to [\#strip](String.downloaded.ruby_doc#method-i-strip) for the
360
- # definition of whitespace.
361
- #
362
- # ```ruby
363
- # " hello ".lstrip! #=> "hello "
364
- # "hello ".lstrip! #=> nil
365
- # "hello".lstrip! #=> nil
366
- # ```
367
- def lstrip!: () -> String?
368
-
369
- def match: (Regexp | String arg0) -> MatchData?
370
- | (Regexp | String arg0, ?Integer arg1) -> MatchData?
371
-
372
- def match?: (Regexp | String arg0) -> bool
373
- | (Regexp | String arg0, ?Integer arg1) -> bool
374
-
375
- # Returns the successor to *str* . The successor is calculated by
376
- # incrementing characters starting from the rightmost alphanumeric (or the
377
- # rightmost character if there are no alphanumerics) in the string.
378
- # Incrementing a digit always results in another digit, and incrementing a
379
- # letter results in another letter of the same case. Incrementing
380
- # nonalphanumerics uses the underlying character set’s collating sequence.
381
- #
382
- # If the increment generates a “carry,” the character to the left of it is
383
- # incremented. This process repeats until there is no carry, adding an
384
- # additional character if necessary.
385
- #
386
- # ```ruby
387
- # "abcd".succ #=> "abce"
388
- # "THX1138".succ #=> "THX1139"
389
- # "<<koala>>".succ #=> "<<koalb>>"
390
- # "1999zzz".succ #=> "2000aaa"
391
- # "ZZZ9999".succ #=> "AAAA0000"
392
- # "***".succ #=> "**+"
393
- # ```
394
- def next: () -> String
395
-
396
- # Equivalent to `String#succ`, but modifies the receiver in place.
397
- def next!: () -> String
398
-
399
- # Treats leading characters of *str* as a string of octal digits (with an
400
- # optional sign) and returns the corresponding number. Returns 0 if the
401
- # conversion fails.
402
- #
403
- # ```ruby
404
- # "123".oct #=> 83
405
- # "-377".oct #=> -255
406
- # "bad".oct #=> 0
407
- # "0377bad".oct #=> 255
408
- # ```
409
- #
410
- # If `str` starts with `0`, radix indicators are honored. See
411
- # Kernel\#Integer.
412
- def oct: () -> Integer
413
-
414
- # Returns the `Integer` ordinal of a one-character string.
415
- #
416
- # ```ruby
417
- # "a".ord #=> 97
418
- # ```
419
- def ord: () -> Integer
420
-
421
- def partition: (Regexp | String arg0) -> [ String, String, String ]
422
-
423
- def `prepend`: (String arg0) -> String
424
-
425
- def replace: (String arg0) -> String
426
-
427
- # Returns a new string with the characters from *str* in reverse order.
428
- #
429
- # ```ruby
430
- # "stressed".reverse #=> "desserts"
431
- # ```
432
- def reverse: () -> String
433
-
434
- def rindex: (String | Regexp arg0, ?Integer arg1) -> Integer?
435
-
436
- def rjust: (Integer arg0, ?String arg1) -> String
437
-
438
- def rpartition: (String | Regexp arg0) -> [ String, String, String ]
439
-
440
- # Returns a copy of the receiver with trailing whitespace removed. See
441
- # also [\#lstrip](String.downloaded.ruby_doc#method-i-lstrip) and
442
- # [\#strip](String.downloaded.ruby_doc#method-i-strip).
443
- #
444
- # Refer to [\#strip](String.downloaded.ruby_doc#method-i-strip) for the
445
- # definition of whitespace.
446
- #
447
- # ```ruby
448
- # " hello ".rstrip #=> " hello"
449
- # "hello".rstrip #=> "hello"
450
- # ```
451
- def rstrip: () -> String
452
-
453
- # Removes trailing whitespace from the receiver. Returns the altered
454
- # receiver, or `nil` if no change was made. See also
455
- # [\#lstrip\!](String.downloaded.ruby_doc#method-i-lstrip-21) and
456
- # [\#strip\!](String.downloaded.ruby_doc#method-i-strip-21).
457
- #
458
- # Refer to [\#strip](String.downloaded.ruby_doc#method-i-strip) for the
459
- # definition of whitespace.
460
- #
461
- # ```ruby
462
- # " hello ".rstrip! #=> " hello"
463
- # " hello".rstrip! #=> nil
464
- # "hello".rstrip! #=> nil
465
- # ```
466
- def rstrip!: () -> String
467
-
468
- def scan: (Regexp | String arg0) -> ::Array[String | ::Array[String]]
469
- | (Regexp | String arg0) { () -> untyped } -> ::Array[String | ::Array[String]]
470
-
471
- def scrub: (?String arg0) -> String
472
- | (?String arg0) { (untyped arg0) -> untyped } -> String
473
-
474
- def scrub!: (?String arg0) -> String
475
- | (?String arg0) { (untyped arg0) -> untyped } -> String
476
-
477
- def setbyte: (Integer arg0, Integer arg1) -> Integer
478
-
479
- # Returns the character length of *str* .
480
- def size: () -> Integer
481
-
482
- def slice!: (Integer arg0, ?Integer arg1) -> String?
483
- | (::Range[Integer] | Regexp arg0) -> String?
484
- | (Regexp arg0, ?Integer arg1) -> String?
485
- | (Regexp arg0, ?String arg1) -> String?
486
- | (String arg0) -> String?
487
-
488
- def split: (?Regexp | String arg0, ?Integer arg1) -> ::Array[String]
489
- | (?Integer arg0) -> ::Array[String]
490
-
491
- def squeeze: (?String arg0) -> String
492
-
493
- def squeeze!: (?String arg0) -> String
494
-
495
- def start_with?: (*String arg0) -> bool
496
-
497
- # Returns a copy of the receiver with leading and trailing whitespace
498
- # removed.
499
- #
500
- # Whitespace is defined as any of the following characters: null,
501
- # horizontal tab, line feed, vertical tab, form feed, carriage return,
502
- # space.
503
- #
504
- # ```ruby
505
- # " hello ".strip #=> "hello"
506
- # "\tgoodbye\r\n".strip #=> "goodbye"
507
- # "\x00\t\n\v\f\r ".strip #=> ""
508
- # "hello".strip #=> "hello"
509
- # ```
510
- def strip: () -> String
511
-
512
- # Removes leading and trailing whitespace from the receiver. Returns the
513
- # altered receiver, or `nil` if there was no change.
514
- #
515
- # Refer to [\#strip](String.downloaded.ruby_doc#method-i-strip) for the
516
- # definition of whitespace.
517
- #
518
- # ```ruby
519
- # " hello ".strip! #=> "hello"
520
- # "hello".strip! #=> nil
521
- # ```
522
- def strip!: () -> String
523
-
524
- def sub: (Regexp | String arg0, ?String | Hash[String, String] arg1) -> String
525
- | (Regexp | String arg0) { (String arg0) -> untyped } -> String
526
-
527
- def sub!: (Regexp | String arg0, ?String arg1) -> String
528
- | (Regexp | String arg0) { (String arg0) -> untyped } -> String
529
-
530
- # Returns the successor to *str* . The successor is calculated by
531
- # incrementing characters starting from the rightmost alphanumeric (or the
532
- # rightmost character if there are no alphanumerics) in the string.
533
- # Incrementing a digit always results in another digit, and incrementing a
534
- # letter results in another letter of the same case. Incrementing
535
- # nonalphanumerics uses the underlying character set’s collating sequence.
536
- #
537
- # If the increment generates a “carry,” the character to the left of it is
538
- # incremented. This process repeats until there is no carry, adding an
539
- # additional character if necessary.
540
- #
541
- # ```ruby
542
- # "abcd".succ #=> "abce"
543
- # "THX1138".succ #=> "THX1139"
544
- # "<<koala>>".succ #=> "<<koalb>>"
545
- # "1999zzz".succ #=> "2000aaa"
546
- # "ZZZ9999".succ #=> "AAAA0000"
547
- # "***".succ #=> "**+"
548
- # ```
549
- def succ: () -> String
550
-
551
- def succ!: () -> String
552
-
553
- def sum: (?Integer arg0) -> Integer
554
-
555
- # Returns a copy of *str* with uppercase alphabetic characters converted
556
- # to lowercase and lowercase characters converted to uppercase.
557
- #
558
- # See [\#downcase](String.downloaded.ruby_doc#method-i-downcase) for
559
- # meaning of `options` and use with different encodings.
560
- #
561
- # ```ruby
562
- # "Hello".swapcase #=> "hELLO"
563
- # "cYbEr_PuNk11".swapcase #=> "CyBeR_pUnK11"
564
- # ```
565
- def swapcase: () -> String
566
-
567
- # Equivalent to `String#swapcase`, but modifies the receiver in place,
568
- # returning *str* , or `nil` if no changes were made.
569
- #
570
- # See [\#downcase](String.downloaded.ruby_doc#method-i-downcase) for
571
- # meaning of `options` and use with different encodings.
572
- def swapcase!: () -> String?
573
-
574
- # Returns a complex which denotes the string form. The parser ignores
575
- # leading whitespaces and trailing garbage. Any digit sequences can be
576
- # separated by an underscore. Returns zero for null or garbage string.
577
- #
578
- # ```ruby
579
- # '9'.to_c #=> (9+0i)
580
- # '2.5'.to_c #=> (2.5+0i)
581
- # '2.5/1'.to_c #=> ((5/2)+0i)
582
- # '-3/2'.to_c #=> ((-3/2)+0i)
583
- # '-i'.to_c #=> (0-1i)
584
- # '45i'.to_c #=> (0+45i)
585
- # '3-4i'.to_c #=> (3-4i)
586
- # '-4e2-4e-2i'.to_c #=> (-400.0-0.04i)
587
- # '-0.0-0.0i'.to_c #=> (-0.0-0.0i)
588
- # '1/2+3/4i'.to_c #=> ((1/2)+(3/4)*i)
589
- # 'ruby'.to_c #=> (0+0i)
590
- # ```
591
- #
592
- # See [Kernel](https://ruby-doc.org/core-2.6.3/Kernel.html).Complex.
593
- def to_c: () -> Complex
594
-
595
- # Returns the result of interpreting leading characters in *str* as a
596
- # floating point number. Extraneous characters past the end of a valid
597
- # number are ignored. If there is not a valid number at the start of *str*
598
- # , `0.0` is returned. This method never raises an exception.
599
- #
600
- # ```ruby
601
- # "123.45e1".to_f #=> 1234.5
602
- # "45.67 degrees".to_f #=> 45.67
603
- # "thx1138".to_f #=> 0.0
604
- # ```
605
- def to_f: () -> Float
606
-
607
- def to_i: (?Integer arg0) -> Integer
608
-
609
- # Returns the result of interpreting leading characters in `str` as a
610
- # rational. Leading whitespace and extraneous characters past the end of a
611
- # valid number are ignored. Digit sequences can be separated by an
612
- # underscore. If there is not a valid number at the start of `str`, zero
613
- # is returned. This method never raises an exception.
614
- #
615
- # ```ruby
616
- # ' 2 '.to_r #=> (2/1)
617
- # '300/2'.to_r #=> (150/1)
618
- # '-9.2'.to_r #=> (-46/5)
619
- # '-9.2e2'.to_r #=> (-920/1)
620
- # '1_234_567'.to_r #=> (1234567/1)
621
- # '21 June 09'.to_r #=> (21/1)
622
- # '21/06/09'.to_r #=> (7/2)
623
- # 'BWV 1079'.to_r #=> (0/1)
624
- # ```
625
- #
626
- # NOTE: “0.3”.to\_r isn’t the same as 0.3.to\_r. The former is equivalent
627
- # to “3/10”.to\_r, but the latter isn’t so.
628
- #
629
- # "0.3".to_r == 3/10r #=> true
630
- # 0.3.to_r == 3/10r #=> false
631
- #
632
- # See also Kernel\#Rational.
633
- def to_r: () -> Rational
634
-
635
- # Returns `self` .
636
- #
637
- # If called on a subclass of [String](String.downloaded.ruby_doc),
638
- # converts the receiver to a [String](String.downloaded.ruby_doc) object.
639
- def to_s: () -> String
640
-
641
- # Returns `self` .
642
- #
643
- # If called on a subclass of [String](String.downloaded.ruby_doc),
644
- # converts the receiver to a [String](String.downloaded.ruby_doc) object.
645
- def to_str: () -> String
646
-
647
- # Returns the `Symbol` corresponding to *str* , creating the symbol if it
648
- # did not previously exist. See `Symbol#id2name` .
649
- #
650
- # ```ruby
651
- # "Koala".intern #=> :Koala
652
- # s = 'cat'.to_sym #=> :cat
653
- # s == :cat #=> true
654
- # s = '@cat'.to_sym #=> :@cat
655
- # s == :@cat #=> true
656
- # ```
657
- #
658
- # This can also be used to create symbols that cannot be represented using
659
- # the `:xxx` notation.
660
- #
661
- # ```ruby
662
- # 'cat and dog'.to_sym #=> :"cat and dog"
663
- # ```
664
- def to_sym: () -> Symbol
665
-
666
- def tr: (String arg0, String arg1) -> String
667
-
668
- def tr!: (String arg0, String arg1) -> String?
669
-
670
- def tr_s: (String arg0, String arg1) -> String
671
-
672
- def tr_s!: (String arg0, String arg1) -> String?
673
-
674
- def unpack: (String arg0) -> ::Array[(Integer | Float | String)?]
675
-
676
- # Returns a copy of *str* with all lowercase letters replaced with their
677
- # uppercase counterparts.
678
- #
679
- # See [\#downcase](String.downloaded.ruby_doc#method-i-downcase) for
680
- # meaning of `options` and use with different encodings.
681
- #
682
- # ```ruby
683
- # "hEllO".upcase #=> "HELLO"
684
- # ```
685
- def upcase: () -> String
686
-
687
- # Upcases the contents of *str* , returning `nil` if no changes were made.
688
- #
689
- # See [\#downcase](String.downloaded.ruby_doc#method-i-downcase) for
690
- # meaning of `options` and use with different encodings.
691
- def upcase!: () -> String?
692
-
693
- def upto: [Bool] (String arg0, ?Bool arg1) -> ::Enumerator[String, self]
694
- | [Bool] (String arg0, ?Bool arg1) { (String arg0) -> untyped } -> String
695
-
696
- # Returns true for a string which is encoded correctly.
697
- #
698
- # ```ruby
699
- # "\xc2\xa1".force_encoding("UTF-8").valid_encoding? #=> true
700
- # "\xc2".force_encoding("UTF-8").valid_encoding? #=> false
701
- # "\x80".force_encoding("UTF-8").valid_encoding? #=> false
702
- # ```
703
- def valid_encoding?: () -> bool
704
-
705
- def self.try_convert: (Object obj) -> String?
706
-
707
- def slice: (Integer arg0, ?Integer arg1) -> String?
708
- | (::Range[Integer] | Regexp arg0) -> String?
709
- | (Regexp arg0, ?Integer arg1) -> String?
710
- | (Regexp arg0, ?String arg1) -> String?
711
- | (String arg0) -> String?
712
-
713
- def encode: (
714
- ?(Encoding | String) encoding,
715
- ?(Encoding | String) from_encoding,
716
- ?invalid: :replace ?,
717
- ?undef: :replace ?,
718
- ?replace: String,
719
- ?fallback: Hash[String, String] | Proc | Method,
720
- ?xml: :text | :attr,
721
- ?universal_newline: TrueClass,
722
- ?cr_newline: TrueClass,
723
- ?crlf_newline: TrueClass
724
- ) -> String
725
-
726
- def encode!: (
727
- ?(Encoding | String) encoding,
728
- ?(Encoding | String) from_encoding,
729
- ?invalid: :replace ?,
730
- ?undef: :replace ?,
731
- ?replace: String,
732
- ?fallback: Hash[String, String] | Proc | Method,
733
- ?xml: :text | :attr,
734
- ?universal_newline: TrueClass,
735
- ?cr_newline: TrueClass,
736
- ?crlf_newline: TrueClass
737
- ) -> self
738
-
739
- def +@: () -> String
740
-
741
- def -@: () -> String
742
-
743
- def unicode_normalize: (?(:nfc | :nfd | :nfkc | :nfkd)) -> String
744
-
745
- def unicode_normalize!: (?(:nfc | :nfd | :nfkc | :nfkd)) -> String
746
-
747
- def casecmp?: (String other) -> bool
748
- | (untyped other) -> nil
749
-
750
- def []=: (Integer pos, String new_str) -> String
751
- | (Integer begin_pos, Integer end_pos, String new_str) -> String
752
- | (::Range[Integer] range, String new_str) -> String
753
- | (Regexp regexp, String new_str) -> String
754
- | (Regexp regexp, Integer capture, String new_str) -> String
755
- | (Regexp regexp, String name, String new_str) -> String
756
- | (String other_str, String new_str) -> String
757
-
758
- def undump: () -> String
759
-
760
- def grapheme_clusters: () -> ::Array[::String]
761
-
762
- def reverse!: () -> String
763
-
764
- def each_grapheme_cluster: () { (String grapheme) -> untyped } -> self
765
- | () -> ::Enumerator[String, self]
766
-
767
- def unpack1: (String format) -> (Integer | Float | String | nil)
768
-
769
- def unicode_normalized?: (?(:nfc | :nfd | :nfkc | :nfkd)) -> bool
770
- end