From: Roger Pack Date: 2011-05-20T00:27:00+09:00 Subject: [ruby-core:36339] [Ruby 1.9 - Feature #4086] Feature request: add String#contain? and {Enumerable,Array}#contain? methods Issue #4086 has been updated by Roger Pack. Ok I am updating to clarify this. The gist of the code change would be this (patch attached): module Enumerable alias contain? include? end class String alias contain? include? end Which would allow for this to work: [1,2,3].contain? 3 "a long sentence".contain? "sentence" s.each_line { |line| if line.contain? 'abc' ... end } Which feels quite natural to me, and is the method name that I typically "reach for" first, only to have to load some other library to get it. Benoit wrote: >> Since ruby is typically not averse to several ways to do the same thing (example: Array#{detect,find}, Array#{collect,map} etc.) > I personally disagree to this, such basic methods duplicated seems bad design for readers. I like TMTOWTDI, but this is just confusing. In this case I feel like it would be ok, though I am traditionally not a big fan of method duplication. I also feel like it makes more sense to do both String and Enumerable at the same time since they have an "include?" method, so to keep it the same there. Any feedback? Thanks! -roger- ---------------------------------------- Feature #4086: Feature request: add String#contain? and {Enumerable,Array}#contain? methods http://redmine.ruby-lang.org/issues/4086 Author: Roger Pack Status: Open Priority: Normal Assignee: Category: Target version: =begin Hello all. I debated this suggestion previously on ruby talk ( http://www.ruby-forum.com/topic/217473 ) and nobody seemed to have negative feedback, so here goes... Currently Strings and Enumerables have a contain? method for searching for if one includes another. I tend to "reach for" an include? method for the same, since it makes more sense in my head. For instance "is this string included in that one? Does this array include this member?" Since ruby is typically not averse to several ways to do the same thing (example: Array#{detect,find}, Array#{collect,map} etc.) I propose that new methods be added of String#contain? and {Enumerable,Array}#contain? I'd be happy to code up a patch if it had a chance of being accepted. Feedback welcome. Cheers! -roger =end -- http://redmine.ruby-lang.org