loading...

Discussion on: Ruby 3 - Set Literal

Collapse
thepeoplesbourgeois profile image
Josh

Plus, the %<char> sigil syntax is a conversion operation on a string literal (and following the percent sign immediately by a paired closure, e.g., %["Let's make s'mores", Cathy said] creates an interpolated string literal where neither the " nor ' characters need to be escaped). It's a clever idea, but it would be a nontrivial amount of reworking to have MRI begin treating the enclosed contents of this syntax as a discrete set of typed data for the case of a Set object.

I might as well also say it here, to avoid double-commenting: The block syntax as you have it written in

[1, 2, 3].any? { 1 }

would return true even if you called #all? with that block, as the expression evaluates to a truthy value (an instance of Numeric), not as a value against which each value should be compared

Collapse
citizen428 profile image
Michael Kohl

I might as well also say it here, to avoid double-commenting

That's slightly confusing, since this comment gets nested under mine, but refers to the actual article.

Thread Thread
thepeoplesbourgeois profile image
Josh

Apologies for the confusion

Collapse
baweaver profile image
Brandon Weaver Author
[1, 2, 3].any? { 1 }

Regarding this, yes, that was the point of that example. It's ambiguous. Is it a set? Is it a block? For me I know it'll probably be called a block but it's an edge case to watch out for.