summaryrefslogtreecommitdiff
path: root/spec/ruby/library/set/fixtures
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/set/fixtures')
-rw-r--r--spec/ruby/library/set/fixtures/set_like.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/ruby/library/set/fixtures/set_like.rb b/spec/ruby/library/set/fixtures/set_like.rb
new file mode 100644
index 0000000000..46f61a451e
--- /dev/null
+++ b/spec/ruby/library/set/fixtures/set_like.rb
@@ -0,0 +1,31 @@
+require 'set'
+
+module SetSpecs
+ # This class is used to test the interaction of "Set-like" objects with real Sets
+ #
+ # These "Set-like" objects reply to is_a?(Set) with true and thus real Set objects are able to transparently
+ # interoperate with them in a duck-typing manner.
+ class SetLike
+ include Enumerable
+
+ def is_a?(klass)
+ super || klass == ::Set
+ end
+
+ def initialize(entries)
+ @entries = entries
+ end
+
+ def each(&block)
+ @entries.each(&block)
+ end
+
+ def inspect
+ "#<#{self.class}: {#{map(&:inspect).join(", ")}}>"
+ end
+
+ def size
+ @entries.size
+ end
+ end
+end