examples/enumerating.rb in protocol-1.0.1 vs examples/enumerating.rb in protocol-2.0.0

- old
+ new

@@ -1,15 +1,9 @@ -require 'protocol' +#!/usr/bin/env ruby -Enumerating = Protocol do - # Iterate over each element of this Enumerating class and pass it to the - # _block_. - def each(&block) end +require 'protocol/core' - include Enumerable -end - begin class FailAry def initialize @ary = [1, 2, 3] end @@ -17,13 +11,14 @@ def each() end conform_to Enumerating end - puts "Should have thrown Protocol::CheckFailed!" rescue Protocol::CheckFailed => e p e # => "Enumerating#each(0&): expected a block argument for FailAry" +else + puts "Should have thrown Protocol::CheckFailed!" end class Ary def initialize @ary = [1, 2, 3] @@ -37,11 +32,9 @@ end puts Ary.new.map { |x| x * x }.inspect + " ([1, 4, 9])" puts Ary.conform_to?(Enumerating).to_s + " (true)" puts Ary.new.conform_to?(Enumerating).to_s + " (true)" - -Enumerating.check_failure :none class FailAry2 def initialize @ary = [1, 2, 3] end