Sha256: 68652aa0fce9b10d1550fde7a0b517de4727cf000404cc2e55481a64394e8a45

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require 'protocol'

# Protocol version of the Comparable module, that actually checks, if #<=>
# was implemented by the including (conforming) class.
Comparing = Protocol do
  # Compares _self_ with _other_ and returns -1, 0, or +1 depending on whether
  # _self_ is less than, equal to, or greater than _other_.
  def <=>(other) end

  include Comparable
end

# Protocol version of the Enumerable module, that actually checks, if #each
# was implemented by the including (conforming) class.
Enumerating = Protocol do
  # Iterate over each element of this Enumerating class and pass it to the
  # _block_. Because protocol cannot determine if a block is expected from a
  # C-function, I left it out of the specification for now.
  understand :each

  include Enumerable
end

# Checks if indexing behaviour exists as in Array or Hash.
Indexing = Protocol do
  understand :[]

  understand :[]=
end

Synchronizing = Protocol do
  def lock() end

  def unlock() end

  implementation

  def synchronize
    lock
    begin
      yield
    ensure
      unlock
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
protocol-2.0.1 lib/protocol/core.rb
protocol-2.0.0 lib/protocol/core.rb