summaryrefslogtreecommitdiff
path: root/lib/prism
diff options
context:
space:
mode:
authorUfuk Kayserilioglu <[email protected]>2024-03-06 14:36:47 -0500
committergit <[email protected]>2024-03-06 21:37:53 +0000
commit8d191a9f57fa6ff86f63c98e99be68ed86f3052c (patch)
tree28749c2c01ee32fcbdd0a54d823691d7798041bb /lib/prism
parent3ad17b3beceb143a3e9fd5374c2e2532f42bf566 (diff)
[ruby/prism] Move polyfill to separate file to type-check it independently.
https://github.com/ruby/prism/commit/2a583b041b
Diffstat (limited to 'lib/prism')
-rw-r--r--lib/prism/polyfill/string.rb12
-rw-r--r--lib/prism/prism.gemspec1
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/prism/polyfill/string.rb b/lib/prism/polyfill/string.rb
new file mode 100644
index 0000000000..582266d956
--- /dev/null
+++ b/lib/prism/polyfill/string.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+# Polyfill for String#unpack1 with the offset parameter.
+if String.instance_method(:unpack1).parameters.none? { |_, name| name == :offset }
+ String.prepend(
+ Module.new {
+ def unpack1(format, offset: 0) # :nodoc:
+ offset == 0 ? super(format) : self[offset..].unpack1(format) # steep:ignore
+ end
+ }
+ )
+end
diff --git a/lib/prism/prism.gemspec b/lib/prism/prism.gemspec
index 1ad2da35c4..d43fcfd36b 100644
--- a/lib/prism/prism.gemspec
+++ b/lib/prism/prism.gemspec
@@ -87,6 +87,7 @@ Gem::Specification.new do |spec|
"lib/prism/parse_result/comments.rb",
"lib/prism/parse_result/newlines.rb",
"lib/prism/pattern.rb",
+ "lib/prism/polyfill/string.rb",
"lib/prism/serialize.rb",
"lib/prism/translation.rb",
"lib/prism/translation/parser.rb",