Index: enum.c
===================================================================
--- enum.c (revision 31895)
+++ enum.c (working copy)
@@ -1595,6 +1595,7 @@
/*
* call-seq:
* enum.include?(obj) -> true or false
+ * enum.contain?(obj) -> true or false
* enum.member?(obj) -> true or false
*
* Returns true
if any member of enum equals
@@ -2697,6 +2698,7 @@
rb_define_method(rb_mEnumerable, "minmax_by", enum_minmax_by, 0);
rb_define_method(rb_mEnumerable, "member?", enum_member, 1);
rb_define_method(rb_mEnumerable, "include?", enum_member, 1);
+ rb_define_method(rb_mEnumerable, "contain?", enum_member, 1);
rb_define_method(rb_mEnumerable, "each_with_index", enum_each_with_index, -1);
rb_define_method(rb_mEnumerable, "reverse_each", enum_reverse_each, -1);
rb_define_method(rb_mEnumerable, "each_entry", enum_each_entry, -1);
Index: string.c
===================================================================
--- string.c (revision 31895)
+++ string.c (working copy)
@@ -4194,6 +4194,7 @@
/*
* call-seq:
* str.include? other_str -> true or false
+ * str.contain? other_str -> true or false
*
* Returns true
if str contains the given string or
* character.
@@ -7790,6 +7791,7 @@
rb_define_method(rb_cString, "ord", rb_str_ord, 0);
rb_define_method(rb_cString, "include?", rb_str_include, 1);
+ rb_define_method(rb_cString, "contain?", rb_str_include, 1);
rb_define_method(rb_cString, "start_with?", rb_str_start_with, -1);
rb_define_method(rb_cString, "end_with?", rb_str_end_with, -1);
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb (revision 31895)
+++ test/ruby/test_array.rb (working copy)
@@ -866,6 +866,11 @@
assert(!a.include?('ca'))
assert(!a.include?([1,2]))
end
+
+ def test_contain?
+ a = @cls[ 'cat' ]
+ assert(a.contain?('cat'))
+ end
def test_index
a = @cls[ 'cat', 99, /a/, 99, @cls[ 1, 2, 3] ]
Index: test/ruby/test_enum.rb
===================================================================
--- test/ruby/test_enum.rb (revision 31895)
+++ test/ruby/test_enum.rb (working copy)
@@ -81,6 +81,11 @@
assert_equal(24, @obj.inject(2) {|z, x| z * x })
assert_equal(24, @obj.inject(2, :*) {|z, x| z * x })
end
+
+ def test_contain
+ assert(@obj.include?(3))
+ assert(@obj.contain?(3))
+ end
def test_partition
assert_equal([[1, 3, 1], [2, 2]], @obj.partition {|x| x % 2 == 1 })
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb (revision 31895)
+++ test/ruby/test_string.rb (working copy)
@@ -774,6 +774,13 @@
assert(!S("foobar").include?(S("baz")))
assert(!S("foobar").include?(?z))
end
+
+ def test_contain?
+ assert( S("foobar").contain?(?f))
+ assert( S("foobar").contain?(S("foo")))
+ assert(!S("foobar").contain?(S("baz")))
+ assert(!S("foobar").contain?(?z))
+ end
def test_index
assert_equal(0, S("hello").index(?h))