I recently discovered that in Python, you can do this:
array = [1, 2, 3, 4]
if 3 in array:
print("Yep!")
Then, I thought to myself: "Mh, why is it different in Ruby? if 3 in array
is more readable than if array.include? 3
." Then, I realized, that Ruby is pure OOP and this approach is keyword-based.
But still, I am wondering. If the Python approach is not OOP, why can't there be another, shorter way in Ruby that is even more readable? When thinking, I don't think "Does this list include that element?", but "Is this element in that list?".
Let's assume, the following code was possible:
array = [1, 2, 3, 4]
if 3.in? array
print "Yep!
end
I see that it is a turn-around from list.method(element)
to element.method(list)
.
So, I am wondering: Which ruby principles/rules speak against the above-metioned code?
EDIT: Oops, I wrote "keyboard-based" but meant of course "keyword-based". To emphasize this: I am not looking for methods that behave like the in? method; I am looking for reasons why it is not implemented in Ruby that way.