Skip to content
loading...

Use Kotlin's / groovy's `it` in Ruby

hanachin profile image Seiei Miyagi twitter logo github logo Updated on ・1 min read

I made a gem "thats_it", with this gem, you can use it method to get a single parameter of the block.

require "thats_it"

p [1, 2, 3].map { it * 2 }
# [2, 4, 6]

https://github.com/hanachin/thats_it/

How it works?

Basic idea is rewrites the block's iseq before call it.

# rewrites this block ↓
[1, 2, 3].map { it * 2 }

#          to this ↓
[1, 2, 3].map {|it| it * 2 }

I wrote a implementation details in Japanese.
https://qiita.com/hanachin_/items/8df68325142d46a7fb0b

If you interested, you can read through Google translate.
https://translate.google.com/translate?hl=ja&sl=ja&tl=en&u=https%3A%2F%2Fqiita.com%2Fhanachin_%2Fitems%2F8df68325142d46a7fb0b

twitter logo DISCUSS
Discussion
markdown guide
Classic DEV Post from Aug 6 '19

What to put in your portfolio as a beginner web dev

Seiei Miyagi profile image
こんにけは