Sha256: 52ca260e79241dc91868d693e9404205150e300594df06100c94903399b4efba

Contents?: true

Size: 536 Bytes

Versions: 5

Compression:

Stored size: 536 Bytes

Contents

# frozen_string_literal: true

# 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:
        offset == 0 ? super(format) : self[offset..].unpack1(format) # steep:ignore
      end
    }
  )
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
prism-1.2.0 lib/prism/polyfill/unpack1.rb
prism-1.1.0 lib/prism/polyfill/unpack1.rb
prism-1.0.0 lib/prism/polyfill/unpack1.rb
prism-0.30.0 lib/prism/polyfill/unpack1.rb
prism-0.28.0 lib/prism/polyfill/unpack1.rb