Sha256: 38d3691b92ce738dde3fb6db2044a148dbe2aa13d1210270b298bd1aeecf7d18

Contents?: true

Size: 748 Bytes

Versions: 58

Compression:

Stored size: 748 Bytes

Contents

require 'mspec/guards/feature'

class Object
  # Helper to handle String encodings. The +str+ and +encoding+ parameters
  # must be Strings and an ArgumentError will be raised if not. This ensures
  # that the encode() helper can be used regardless of whether Encoding exits.
  # The helper is a no-op (i.e. passes through +str+ unmodified) if the
  # :encoding feature is not enabled (see with_feature guard).  If the
  # :encoding feature is enabled, +str+.force_encoding(+encoding+) is called.
  def encode(str, encoding)
    unless str.is_a? String and encoding.is_a? String
      raise ArgumentError, "encoding name must be a String"
    end

    if FeatureGuard.enabled? :encoding
      str.force_encoding encoding
    end

    str
  end
end

Version data entries

58 entries across 58 versions & 3 rubygems

Version Path
rhodes-5.5.18 lib/extensions/mspec/mspec/helpers/encode.rb
rhodes-5.5.17 lib/extensions/mspec/mspec/helpers/encode.rb
rhodes-5.5.15 lib/extensions/mspec/mspec/helpers/encode.rb
rhodes-5.5.0.22 lib/extensions/mspec/mspec/helpers/encode.rb
rhodes-5.5.2 lib/extensions/mspec/mspec/helpers/encode.rb
rhodes-5.5.0.7 lib/extensions/mspec/mspec/helpers/encode.rb
rhodes-5.5.0.3 lib/extensions/mspec/mspec/helpers/encode.rb
rhodes-5.5.0 lib/extensions/mspec/mspec/helpers/encode.rb
tauplatform-1.0.3 lib/extensions/mspec/mspec/helpers/encode.rb
mspec-1.9.1 lib/mspec/helpers/encode.rb
mspec-1.9.0 lib/mspec/helpers/encode.rb
tauplatform-1.0.2 lib/extensions/mspec/mspec/helpers/encode.rb
tauplatform-1.0.1 lib/extensions/mspec/mspec/helpers/encode.rb
mspec-1.8.0 lib/mspec/helpers/encode.rb
mspec-1.7.0 lib/mspec/helpers/encode.rb
mspec-1.6.0 lib/mspec/helpers/encode.rb
mspec-1.5.21 lib/mspec/helpers/encode.rb
mspec-1.5.20 lib/mspec/helpers/encode.rb
mspec-1.5.19 lib/mspec/helpers/encode.rb
mspec-1.5.18 lib/mspec/helpers/encode.rb