https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112014-03-15T16:49:42ZRuby Issue Tracking SystemRuby master - Feature #9585: Add Object#in? to make ruby easier to readhttps://redmine.ruby-lang.org/issues/9585?journal_id=458062014-03-15T16:49:42Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>This probably would not be a big addition and not bother many.</p>
<p>I think it can be readable:</p>
<p>array = [1,2,3,4,5]<br>
if 3.in? array<br>
puts 'Yup, is in the array!'<br>
end</p>
<p>I think one problem may be that it is on a Fixnum here though. Fixnums don't have much.</p>
<p>Also examples like:</p>
<p>if status.in? 1, 2, 127 # better</p>
<p>Don't really seem much better.</p>
<p>I am neutral about this suggestion.</p>
<p>I do think we should point out that this way of counting is opposite to the current way, as<br>
in:</p>
<p>(1..5).include? 3 # => true</p>
<p>With your proposal you would turn this around, in pseudo-code</p>
<p>3.in? 1..5</p>
<p>So one more to add to Cons would be:</p>
<ul>
<li>opposite to the current default way in Ruby.</li>
</ul>