Sha256: a8ba4cb6eb37ec021eaa387b12bdf0c5025d988de045b89f77884ffbef67f7e2
Contents?: true
Size: 881 Bytes
Versions: 2
Compression:
Stored size: 881 Bytes
Contents
#!/usr/bin/env ruby require 'protocol/core' begin class FailAry def initialize @ary = [1, 2, 3] end def each() end conform_to Enumerating end 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] end def each(&block) @ary.each(&block) end conform_to Enumerating 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)" class FailAry2 def initialize @ary = [1, 2, 3] end def each() end conform_to Enumerating end puts FailAry2.conform_to?(Enumerating).to_s + " (false)" puts FailAry2.new.conform_to?(Enumerating).to_s + " (false)"
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
protocol-2.0.1 | examples/enumerating.rb |
protocol-2.0.0 | examples/enumerating.rb |