When to use blocks

前端 未结 3 692
春和景丽
春和景丽 2021-01-31 04:45

I love Ruby blocks! The idea behind them is just very very neat and convenient.

I have just looked back over my code from the past week or so, which is

3条回答
  •  生来不讨喜
    2021-01-31 05:12

    I like this style. It's actually very Ruby-like, and often you'll see projects restructure their code to use this format instead of something less readable.

    Returning values makes sense where returning values makes sense. If you have an Article object, you want article.title to return the title. But for this particular example of callbacks, it's stellar style, and it's good that you know how to use them. I suspect that many new to Ruby will never figure out how to do it well.

提交回复
热议问题