From: "jhilden (Jakob Hilden)" Date: 2012-04-26T17:33:24+09:00 Subject: [ruby-core:44644] [ruby-trunk - Feature #6365][Open] [Feature request] Better readable syntax to check if String is included in Array Issue #6365 has been reported by jhilden (Jakob Hilden). ---------------------------------------- Feature #6365: [Feature request] Better readable syntax to check if String is included in Array https://bugs.ruby-lang.org/issues/6365 Author: jhilden (Jakob Hilden) Status: Open Priority: Normal Assignee: Category: Target version: =begin I find myself constantly wanting to check whether one string is included within an array of strings. It is certainly possible (and also fast) to do that in Ruby with something like this: ["foo", "bar"].include?("foo") But I don't think it reads very nice :( Because what I actually want to test is, whether my string is included in the array and NOT the other way around. What do you think about something like the following two solutions? (({class String # create a new method def included_in?(array) array.include?(self) end # -- OR -- # change the current String#include? method def include?(parameter) if parameter.is_a? Array parameter.include?(self) else super end end end})) I know it's just a minor code vanity issue, but since it's one of Ruby's main features, I wanted to bring it up. The (pseudo) code can also be found here: https://gist.github.com/1181246 =end -- http://bugs.ruby-lang.org/