6 ms·
Rails implements this as `in?` https://github.com/rails/rails/blob/d61baee52adcd1baebe15f1065a0805857571f19/activesupport/lib/active_support/core_ext/object/in
by tyre 11y ago
Rails implements this as `in?`
https://github.com/rails/rails/blob/d61baee52adcd1baebe15f1065a0805857571f19/activesupport/lib/active_support/core_ext/object/inclusion.rb#L10 https://github.com/rails/rails/blob/d61baee52adcd1baebe15f10...
You're welcome to try and merge that into Ruby core itself. That said, "I like whitespace" isn't a good reason to add a new operator over a method. Ruby is object oriented, meaning you are calling methods on objects.
- jmcdonald-ut 11y agoHe addresses this in his post. if x.in? my_set # very ugly With that said, I personally don't agree with the post.
- bhaak 11y agoI don't know what's so ugly about this. I wouldn't call the method "in?" but maybe "element_of?" or "member_of?" but besides that, I don't see the need for an operator.
- fleitz 11y agoThen why have 2 * 4 when you can write 2.multiply_by 4... What I love about ruby is its focus on making programming delightful rather than adhering to weird ass rules like 'Ruby is object oriented, meaning you are calling methods on objects.' that people pretend are laws of physics when really you can break them anytime you want, unlike laws of physics. Similar to the way you can write def foo "bar" end instead of class Kernel def foo "bar" end end
- deleted 11y ago[deleted]
- mpweiher 11y agoSmalltalk messages/methods: a in: set. 2 * 4. Just sayin'
- chris_st 11y agoOf course, but then 2 * 4 + 5. In Smalltalk evaluates to 18.
- mpweiher 11y agoNo, that's 13. You probably meant 4 + 5 * 2. Also: Compilation Order: Smalltalk-78 had perpetuated the post-evaluation of receiver expressions so as to avoid delving into the stack to find the receiver. In the Smalltalk-80 language, however, we encoded the number of arguments in the send instruction. This enabled strictly left- to-right evaluation, and no one has since complained about surprising order of evaluation. We suspect that this change will yield further fruit in the future when someone tries to build a very simple compiler. http://sdmeta.gforge.inria.fr/FreeBooks/BitsOfHistory/BitsOfHistory.pdf http://sdmeta.gforge.inria.fr/FreeBooks/BitsOfHistory/BitsOf... p. 21
- chris_st 11y agoAh, thanks. I sit corrected :-)
- deleted 11y ago[deleted]
- wycats 11y agoThe difference here is that `` literally maps onto a method called `` in Ruby. I find this aspect of Ruby delightful and it's not something I willingly chip away at. Generally speaking, Ruby eschews syntax that invokes a protocol behind the scenes for a consistent 1:1 mapping between method syntax and the methods they invoke.