Recently I was having a discussion with a friend about Ruby's Proc
. You can call a Proc
in one of several ways. One way is to invoke Proc.call
:
p = Proc.new { |x| "hello, #{x}" }
p.call "Bob"
=> "hello, Bob"
Another is to use braces, Proc.[]
:
p ["Bob"]
=> "hello, Bob"
Are there any potential precedence issues here, or are these two statements completely interchangeable? If not, can you provide an example of a context where different results would be provided?