Forum: Ruby error in if

Posted by Mohammed Yasin Rahman (Guest)
on 2012-11-27 15:23
(Received via mailing list)
WHat's the error here?

a = [1,2,3]

if 1 in a
    puts "exists"
end

It gives: test.rb:5: syntax error, unexpected keyword_end, expecting 
$end
Posted by Carlo E. Prelz (Guest)
on 2012-11-27 15:30
(Received via mailing list)
Subject: error in if
  Date: Tue 27 Nov 12 11:22:50PM +0900
Sorry for the delay!

Quoting Mohammed Yasin Rahman (Mohammed-Yasin.Rahman@lip6.fr):

> WHat's the error here?
>
> a = [1,2,3]
>
> if 1 in a
>     puts "exists"
> end
>
> It gives: test.rb:5: syntax error, unexpected keyword_end, expecting $end

"if 1 in a" is not valid Ruby syntax.

A working line #3 could be

if(a.include?(1))

Carlo
Posted by Peter Hickman (Guest)
on 2012-11-27 15:33
(Received via mailing list)
There is no such construction in Ruby (were you thinking about another
language?) try something like

a = [1,2,3]

if a.include?(1)
  puts "exists"
end



On 27 November 2012 14:22, Mohammed Yasin Rahman <
Posted by Mohammed Yasin Rahman (Guest)
on 2012-11-27 15:33
(Received via mailing list)
Yes, I was trying to code like python :). Now it's okay. Thanks
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.