diff options
-rw-r--r-- | lib/prism/polyfill/string.rb | 12 | ||||
-rw-r--r-- | lib/prism/prism.gemspec | 1 | ||||
-rw-r--r-- | prism/templates/lib/prism/serialize.rb.erb | 12 |
3 files changed, 14 insertions, 11 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", diff --git a/prism/templates/lib/prism/serialize.rb.erb b/prism/templates/lib/prism/serialize.rb.erb index 23671d2954..097fb25778 100644 --- a/prism/templates/lib/prism/serialize.rb.erb +++ b/prism/templates/lib/prism/serialize.rb.erb @@ -1,15 +1,5 @@ require "stringio" - -# 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) - end - } - ) -end +require "prism/polyfill/string" module Prism # A module responsible for deserializing parse results. |