ruby/ruby · error · NotImplementedError

Unknown Ruby: #{RUBY_ENGINE}

Error message

Unknown Ruby: #{RUBY_ENGINE}

What it means

NotImplementedError raised by the strscan gem's ruby-side loader (lib/strscan.rb:19) when RUBY_ENGINE is neither 'ruby' (MRI), 'jruby', nor 'truffleruby'. The gem selects a per-engine native implementation (C ext, strscan.jar, or truffleruby bindings); an unrecognized engine means no implementation exists, so requiring 'strscan' fails immediately.

Source

Thrown at ext/strscan/lib/strscan.rb:19

# frozen_string_literal: true

case RUBY_ENGINE
when 'ruby'
  require 'strscan.so'
  require_relative 'strscan/strscan'
when 'jruby'
  require 'strscan.jar'
  JRuby::Util.load_ext('org.jruby.ext.strscan.StringScannerLibrary')
  require_relative 'strscan/strscan'
when 'truffleruby'
  if RUBY_ENGINE_VERSION.to_i >= 34
    require 'strscan/truffleruby'
  else
    $LOAD_PATH.delete __dir__
    require 'strscan'
  end
else
  raise NotImplementedError, "Unknown Ruby: #{RUBY_ENGINE}"
end

View on GitHub (pinned to 0e5b888e1c)

Solutions

  1. Run under a supported engine: MRI (ruby), JRuby (>= the gem's required version), or TruffleRuby
  2. For JRuby with an old engine version, upgrade past the version gate in the loader so the strscan.jar path is taken
  3. On unsupported engines, depend on a pure-Ruby replacement or vendor a scanner implemented with Regexp instead of the strscan gem
  4. If you maintain a forked engine, add a branch for your RUBY_ENGINE or set it to report 'ruby' only if the C ABI truly matches

Example fix

# before (Gemfile forces native gem on an unsupported engine)
gem 'strscan', force_ruby_platform: true # require 'strscan' => NotImplementedError under exotic engine

# after
gem 'strscan' # let bundler pick the precompiled platform gem for MRI/JRuby/TruffleRuby
# or, on unsupported engines, avoid strscan:
class SimpleScanner
  def initialize(s) = (@s = s)
  def scan(re) = (@s.slice!(/\A#{re}/))
end
Defensive patterns

Strategy: type-guard

Validate before calling

unless %w[ruby jruby truffleruby].include?(RUBY_ENGINE)
  abort "strscan unsupported on #{RUBY_ENGINE}"
end
require 'strscan'

Type guard

def strscan_supported? = %w[ruby jruby truffleruby].include?(RUBY_ENGINE)

Try / catch

begin
  require 'strscan'
rescue NotImplementedError
  require_relative 'my_fallback_scanner' # pure-Ruby regex-based scanner
end

Prevention

When it happens

Trigger: Requiring the strscan gem source under an exotic engine (e.g. rbx/Rubinius relics, opal, mruby-based runtimes); a bundler setup that forces the ruby-platform variant of the gem (force_ruby_platform: true) on an engine the gem does not know; vendoring the gem into a custom embedded Ruby build whose RUBY_ENGINE was renamed.

Common situations: Custom/compiled Ruby distributions that report a nonstandard RUBY_ENGINE; opal or transpiled-browser environments; switching a project to an experimental engine while gems still pin the C-ext gem rather than a pure-Ruby alternative.

Related errors


AI-assisted analysis of ruby/ruby@0e5b888e1c (2026-08-21). Data as JSON: /api/errors/ed81b527a09da8f0. Report an issue: GitHub.