summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-16 21:51:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-16 21:51:01 +0000
commit75c1cac7f306627ce2a96faa0ca17ffb039bd762 (patch)
tree9bbde912ce8a99ce68eec4a5258b75f3a686e408 /lib/set.rb
parentc89882197ed679e89b120dd328cd053d7ad56094 (diff)
* {ext,lib,test}/**/*.rb: removed trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@27366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb74
1 files changed, 37 insertions, 37 deletions
diff --git a/lib/set.rb b/lib/set.rb
index e0451b65d2..0f94ed9e82 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -4,15 +4,15 @@
#++
# Copyright (c) 2002-2008 Akinori MUSHA <[email protected]>
#
-# Documentation by Akinori MUSHA and Gavin Sinclair.
+# Documentation by Akinori MUSHA and Gavin Sinclair.
#
# All rights reserved. You can redistribute and/or modify it under the same
# terms as Ruby.
#
# $Id$
#
-# == Overview
-#
+# == Overview
+#
# This library provides the Set class, which deals with a collection
# of unordered values with no duplicates. It is a hybrid of Array's
# intuitive inter-operation facilities and Hash's fast lookup. If you
@@ -442,35 +442,35 @@ class Set
end
end
-#
+#
# SortedSet implements a Set that guarantees that it's element are
# yielded in sorted order (according to the return values of their
# #<=> methods) when iterating over them.
-#
+#
# All elements that are added to a SortedSet must respond to the <=>
# method for comparison.
-#
+#
# Also, all elements must be <em>mutually comparable</em>: <tt>el1 <=>
# el2</tt> must not return <tt>nil</tt> for any elements <tt>el1</tt>
# and <tt>el2</tt>, else an ArgumentError will be raised when
# iterating over the SortedSet.
#
# == Example
-#
+#
# require "set"
-#
+#
# set = SortedSet.new([2, 1, 5, 6, 4, 5, 3, 3, 3])
# ary = []
-#
+#
# set.each do |obj|
# ary << obj
# end
-#
+#
# p ary # => [1, 2, 3, 4, 5, 6]
-#
+#
# set2 = SortedSet.new([1, 2, "3"])
# set2.each { |obj| } # => raises ArgumentError: comparison of Fixnum with String failed
-#
+#
class SortedSet < Set
@@setup = false
@@ -495,7 +495,7 @@ class SortedSet < Set
@hash = RBTree.new
super
end
-
+
def add(o)
o.respond_to?(:<=>) or raise ArgumentError, "value must repond to <=>"
super
@@ -580,33 +580,33 @@ end
# == RestricedSet class
# RestricedSet implements a set with restrictions defined by a given
# block.
-#
+#
# === Super class
# Set
-#
+#
# === Class Methods
# --- RestricedSet::new(enum = nil) { |o| ... }
# --- RestricedSet::new(enum = nil) { |rset, o| ... }
# Creates a new restricted set containing the elements of the given
# enumerable object. Restrictions are defined by the given block.
-#
+#
# If the block's arity is 2, it is called with the RestrictedSet
# itself and an object to see if the object is allowed to be put in
# the set.
-#
+#
# Otherwise, the block is called with an object to see if the object
# is allowed to be put in the set.
-#
+#
# === Instance Methods
# --- restriction_proc
# Returns the restriction procedure of the set.
-#
+#
# =end
-#
+#
# class RestricedSet < Set
# def initialize(*args, &block)
# @proc = block or raise ArgumentError, "missing a block"
-#
+#
# if @proc.arity == 2
# instance_eval %{
# def add(o)
@@ -614,7 +614,7 @@ end
# self
# end
# alias << add
-#
+#
# def add?(o)
# if include?(o) || [email protected](self, o)
# nil
@@ -623,19 +623,19 @@ end
# self
# end
# end
-#
+#
# def replace(enum)
# enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
# clear
# enum.each { |o| add(o) }
-#
+#
# self
# end
-#
+#
# def merge(enum)
# enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
# enum.each { |o| add(o) }
-#
+#
# self
# end
# }
@@ -643,12 +643,12 @@ end
# instance_eval %{
# def add(o)
# if @proc.call(o)
-# @hash[o] = true
+# @hash[o] = true
# end
# self
# end
# alias << add
-#
+#
# def add?(o)
# if include?(o) || [email protected](o)
# nil
@@ -659,10 +659,10 @@ end
# end
# }
# end
-#
+#
# super(*args)
# end
-#
+#
# def restriction_proc
# @proc
# end
@@ -1269,33 +1269,33 @@ end
# class TC_RestricedSet < Test::Unit::TestCase
# def test_s_new
# assert_raises(ArgumentError) { RestricedSet.new }
-#
+#
# s = RestricedSet.new([-1,2,3]) { |o| o > 0 }
# assert_equal([2,3], s.sort)
# end
-#
+#
# def test_restriction_proc
# s = RestricedSet.new([-1,2,3]) { |o| o > 0 }
-#
+#
# f = s.restriction_proc
# assert_instance_of(Proc, f)
# assert(f[1])
# assert(!f[0])
# end
-#
+#
# def test_replace
# s = RestricedSet.new(-3..3) { |o| o > 0 }
# assert_equal([1,2,3], s.sort)
-#
+#
# s.replace([-2,0,3,4,5])
# assert_equal([3,4,5], s.sort)
# end
-#
+#
# def test_merge
# s = RestricedSet.new { |o| o > 0 }
# s.merge(-5..5)
# assert_equal([1,2,3,4,5], s.sort)
-#
+#
# s.merge([10,-10,-8,8])
# assert_equal([1,2,3,4,5,8,10], s.sort)
# end