Issue #6365 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)

There were some similar proposals:

  - Object#in? [ruby-core:23543]
  - "in" infix operator [ruby-core:32454]

But matz is not enthusiastic for this kind of proposals.

-- 
Yusuke Endoh <mame / tsg.ne.jp>
----------------------------------------
Feature #6365: [Feature request] Better readable syntax to check if String is included in Array
https://bugs.ruby-lang.org/issues/6365#change-26229

Author: jhilden (Jakob Hilden)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
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/