summaryrefslogtreecommitdiff
path: root/spec/ruby/library/set/fixtures
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-20 20:38:57 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-20 20:38:57 +0000
commit6204e0804b24f1675b49d5880da014411bcfb831 (patch)
treece6c00bf078fc416936ca3cdc972b9b3c1c78dae /spec/ruby/library/set/fixtures
parent58573c33e4720315ed27491e31dcc22892e1ce95 (diff)
Update to ruby/spec@35a9fba
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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