christian christian - 11 months ago 76
Ruby Question

Ruby Curly Brackets for "set" value

What's the difference between these two variations in Ruby

set: example1, "/random/string"


set: example2, -> {"random/string"}

Do they both have the same effect?


Although they look superficially similar they're actually two completely different things.

The first is a simple string, the second is a Proc which returns a string. Many methods in the Ruby world take both, the Proc version is a way of deferring evaluation of something until if and when it's needed.

The -> { ... } notation is shorthand for lambda { ... }, it's called the stabby-lambda operator.