Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of "do | |" in Ruby?

Tags:

ruby

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?

like image 738
pedrozath Avatar asked Jan 29 '11 12:01

pedrozath


People also ask

What does do do in Rails?

The do keyword is used together with the end keyword to delimit a code block.

Do end blocks Ruby?

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.

What does -> mean in Ruby?

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.

What is EOS in Ruby?

EOS means end of string. it is displayed at the end of the string.


1 Answers

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

like image 137
Gareth Avatar answered Sep 23 '22 00:09

Gareth