OneZero
OneZero

Reputation: 11904

How to use conditional to test if a block is passed?

For example, if I want to implement a function that does some work A if a block is passed, or work B if there's no block, how do I write the conditional?

obj.func {#some code} #func does work A
obj.func              #func does work B

Upvotes: 1

Views: 76

Answers (1)

Jorge Israel Peña
Jorge Israel Peña

Reputation: 38576

You can use the block_given? function, if I understood your question correctly.

Upvotes: 6

Related Questions