Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9267431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:32:53+00:00 2026-06-18T14:32:53+00:00

I recently discovered that in Python, you can do this: array = [1, 2,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:32:55+00:00Added an answer on June 18, 2026 at 2:32 pm

    Which ruby principles/rules speak against the above-metioned code?

    It’s not a Ruby principle, but rather the general OOP principle of encapsulation: the Fixnum class should not need to know anything about arrays. However, because Array’s primary responsibility is to contain collections of objects, #in? or #include? clearly falls under Array’s responsibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently discovered that you can set breakpoints in Xcode that will print to
I recently discovered that I can use lambdas to create simple event handlers. I
I recently discovered that in C++ you can overload the function call operator, in
I have recently discovered that I am affected by this bug http://www.mail-archive.com/mono-bugs@lists.ximian.com/msg71515.html Well, at
I recently discovered that an outdated version of Python was causing my Wx app
I recently discovered that different browsers handle the onclick event differently when the Control
I recently discovered that 2 == [2] in JavaScript. As it turns out, this
I recently discovered that you can conditionally assign a value with an if-else block.
I recently discovered that a method in a derived class can only access the
I recently discovered that you can describe an Android custom drawable in an XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.