Sha256: 326e6d830625a5c6190a7c7b8cbb85b9c3f5284833ad60090090aab9cef1283b

Contents?: true

Size: 610 Bytes

Versions: 11

Compression:

Stored size: 610 Bytes

Contents

require 'mspec/guards/guard'

# Despite that these are inverses, the two classes are
# used to simplify MSpec guard reporting modes

class BigEndianGuard < SpecGuard
  def pattern
    [1].pack('L')
  end
  private :pattern

  def match?
    pattern[-1] == 1
  end
end

class LittleEndianGuard < SpecGuard
  def pattern
    [1].pack('L')
  end
  private :pattern

  def match?
    pattern[-1] == 0
  end
end

class Object
  def big_endian
    g = BigEndianGuard.new
    yield if g.yield?
    g.unregister
  end

  def little_endian
    g = LittleEndianGuard.new
    yield if g.yield?
    g.unregister
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mspec-1.0.0 lib/mspec/guards/endian.rb
mspec-1.5.3 lib/mspec/guards/endian.rb
mspec-1.1.0 lib/mspec/guards/endian.rb
mspec-1.3.0 lib/mspec/guards/endian.rb
mspec-1.4.0 lib/mspec/guards/endian.rb
mspec-1.5.0 lib/mspec/guards/endian.rb
mspec-1.1.1 lib/mspec/guards/endian.rb
mspec-1.2.0 lib/mspec/guards/endian.rb
mspec-1.3.1 lib/mspec/guards/endian.rb
mspec-1.5.1 lib/mspec/guards/endian.rb
mspec-1.5.2 lib/mspec/guards/endian.rb