Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby: What's the meaning of keyword "in"

Tags:

ruby

When I find the keyword "in" in ruby first time. I think maybe I can do that: 1 in (0..10) But it look like I cannot use it like that way.

Then I search it in ruby-lang.org, and google it. There is no answer!

What's the meaning of keyword "in" in ruby?

like image 252
colder Avatar asked Jun 18 '09 07:06

colder


1 Answers

You should be able to do the following:

for i in 0..10 do
  puts i
end

The expression 1 in (0..10) that you mention won't work because a constant (1) can't vary over a range - it's a constant! You need to name a variable before the in keyword.

Hope that helps.

See this page as well.

like image 178
Mark Pim Avatar answered Nov 19 '22 08:11

Mark Pim