top | item 42567843

(no title)

jaynetics | 1 year ago

_1 is also a bit of a footgun. It becomes an array of all block params IF the block has an arity > 1 AND no other block param (e.g. _2) is referenced anywhere within the block.

It's an unusually half-baked feature by Ruby's standards. I think there was some hesitation about the name "it" initially, because "it" is an essential method name in rspec, and is used within blocks there.

discuss

order

ryanmjacobs|1 year ago

Oh damn. I have been using `_1`, `_2`, etc. extensively for years... I didn't know about that footgun.

I'd like know if `it` is merely an alias for `_1`, or if protects from this "arity issue" too.

ch4s3|1 year ago

I pity anyone needing to debug a fiddly Rspec problem in the next few years.

ezekg|1 year ago

IIRC, the decision was that it in a block is only ever called without arguments, e.g. map { it * 2 }, and it in Rspec is only ever called with arguments, e.g. it "describes a test" do ... end. So it ended up being a non-issue.