Issue #6365 has been updated by matz (Yukihiro Matsumoto).

Status changed from Assigned to Rejected

You explained you prefer str.included_in?(ary) or str.include?(ary) better because you "don't think it reads very nice".
I consider it very subjective.  Could you elaborate if you really want the feature merged?

I am against str.include?([str1, str2]) because it might confuse users either str contains ALL of str1 and str2 or ANY of them.  included_in? is better in that sense.  But I feel it's ugly.  I know it's VERY subjective.  But you know, Ruby's design itself is very subjective to MY perspective, after all.

Matz.


----------------------------------------
Feature #6365: [Feature request] Better readable syntax to check if String is included in Array
https://bugs.ruby-lang.org/issues/6365#change-26238

Author: jhilden (Jakob Hilden)
Status: Rejected
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"|URL:https://gist.github.com/1181246>))
=end



-- 
http://bugs.ruby-lang.org/