summaryrefslogtreecommitdiff
path: root/lib/prism/polyfill/scan_byte.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/prism/polyfill/scan_byte.rb')
-rw-r--r--lib/prism/polyfill/scan_byte.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/prism/polyfill/scan_byte.rb b/lib/prism/polyfill/scan_byte.rb
new file mode 100644
index 0000000000..2def4572c4
--- /dev/null
+++ b/lib/prism/polyfill/scan_byte.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+require "strscan"
+
+# Polyfill for StringScanner#scan_byte, which didn't exist until Ruby 3.4.
+if !(StringScanner.instance_methods.include?(:scan_byte))
+ StringScanner.include(
+ Module.new {
+ def scan_byte # :nodoc:
+ get_byte&.b&.ord
+ end
+ }
+ )
+end