While reading some Ruby code I saw this:
create_table :talks do |t|
What is this notation |variable|
? What does that do?
And also, where do I find help for these specific subjects like | |
, #{}
, and so on?
The do keyword is used together with the end keyword to delimit a code block.
There are two ways of defining a block in Ruby: The first is using the do.. end keyword, the other is using a pair of curly braces. Do.. end block is mainly used when defining a block of code that spans multiple lines, while curly braces {} are used when defining a block of code that spans a single line.
This answer is not useful. Show activity on this post. In Ruby Programming Language ("Methods, Procs, Lambdas, and Closures"), a lambda defined using -> is called lambda literal. succ = ->(x){ x+1 } succ.call(2) The code is equivalent to the following one.
EOS means end of string. it is displayed at the end of the string.
It's a way of defining arguments for a block, in a similar way to def methodname(arg1, arg2)
A nice explanation of blocks is available from Robert Sosinski
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With