Hacker News new | past | comments | ask | show | jobs | submit login

Rails implements this as `in?`

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.




He addresses this in his post.

  if x.in? my_set   # very ugly
With that said, I personally don't agree with the post.


I 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.


Then 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


The 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.


[deleted]


Smalltalk messages/methods:

   a in: set.
   2 * 4.
Just sayin'


Of course, but then

    2 * 4 + 5.
In Smalltalk evaluates to 18.


No, 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/BitsOf... p. 21


Ah, thanks. I sit corrected :-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: