An 'in' operator for Ruby
rubyhacker.com
An 'in' operator for Ruby
1–10 of 69 posts
Re: An 'in' operator for Ruby
#2Re: An 'in' operator for Ruby
#3https://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.
Re: An 'in' operator for Ruby
#4 if x.in? my_set # very ugly
I guess we disagree there. This is arguably more readable than most languages with `in?` being still just a method.Re: An 'in' operator for Ruby
#5Rails 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.
if x.in? my_set # very ugly
With that said, I personally don't agree with the post.Re: An 'in' operator for Ruby
#6Having said that, I don't agree that it needs to be an operator over a method. I agree that it would be prettier, but methods provide additional benefits like being easy to override or pass as arguments to other methods (like :respond_to?). If you're ok with a method, you can easily monkey patch ruby to support an `in` (or `in?`) method yourself.
Re: An 'in' operator for Ruby
#7I personally wouldn't be in favor of it.
Addition: Arguing that "Ruby isn't English" and then stating conformity to mathematical notation as a benefit seems hypocritical. Programming languages (besides APL, maybe) do not use strict mathematical notation, and we shouldn't want them to.
Re: An 'in' operator for Ruby
#8because it's Japanese https://www.new-bamboo.co.uk/blog/2010/12/17/learning-japane...
Re: An 'in' operator for Ruby
#9Re: An 'in' operator for Ruby
#10> But we also -- perhaps more often? -- ask questions like "Is this item part of this group?" We are asking a question about the item.
Here we are actually asking the group a question about itself. An item would not know a group's contents.