summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/prism/polyfill/string.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/prism/polyfill/string.rb b/lib/prism/polyfill/string.rb
index 582266d956..3fa9b5a0c5 100644
--- a/lib/prism/polyfill/string.rb
+++ b/lib/prism/polyfill/string.rb
@@ -1,7 +1,9 @@
# frozen_string_literal: true
-# Polyfill for String#unpack1 with the offset parameter.
-if String.instance_method(:unpack1).parameters.none? { |_, name| name == :offset }
+# Polyfill for String#unpack1 with the offset parameter. Not all Ruby engines
+# have Method#parameters implemented, so we check the arity instead if
+# necessary.
+if (unpack1 = String.instance_method(:unpack1)).respond_to?(:parameters) ? unpack1.parameters.none? { |_, name| name == :offset } : (unpack1.arity == 1)
String.prepend(
Module.new {
def unpack1(format, offset: 0) # :nodoc: