Crystal: string.include? vs string.includes?

Created on 28 May 2017  路  2Comments  路  Source: crystal-lang/crystal

In Ruby, the method is string.include?, in the singular, no "s" at the end of "include". In Crystal it is string.includes? in the plural. Not sure if on purpose but I thought to point it out.

question

Most helpful comment

It's on purpose. includes? is better grammar, and we don't aim to be compatible with ruby.

All 2 comments

It's on purpose. includes? is better grammar, and we don't aim to be compatible with ruby.

@RX14 suggestion on this... I'm referring to the includes? method on collections. This is one case where including the "s" or not can both be valid depending on context, and it has tripped me up. Here are two examples:

do_something if @widget_collection.includes?(widget)

and

do_something if @widgets.include?(widget)

I've used both of these forms in real-world practice, and both are correct. But the latter form is much more common in my work, and in Crystal it spits out undefined method.

From my experience so far, it seems like Crystal is less enthusiastic about having a lot of aliased methods, and I can appreciate that (like Python's "one right way to do it"), but also strives for nice readability like Ruby. So perhaps there is some undefined happy medium?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asterite picture asterite  路  70Comments

farleyknight picture farleyknight  路  64Comments

akzhan picture akzhan  路  67Comments

asterite picture asterite  路  71Comments

xtagon picture xtagon  路  132Comments