Code Tunning

  • Thread starter Fernando Giannetti
  • Start date
F

Fernando Giannetti

Hi!
there is a better way to do that?

if anArray.include?(id)
state='YES'
else
state='NOT'
end

puts "#{id}: #{state} included"


Thanks!
 
F

Farrel Lifson

2008/12/2 Fernando Giannetti said:
if anArray.include?(id)
state='YES'
else
state='NOT'
end

state = if anArray.include?(id)
'YES'
else
'NO'
end

or

state = anArray.include?(id) ? 'YES' : 'NO'

Farrel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Timing problem 4
Chatbot 0
PWM Issues 0
Can this code be used? Github repository question 0
SyntaxError | Learn Python The Hard Way 1
Problem with code 6
Hid\show group box in asp.net 2
Help with code 0

Members online

Forum statistics

Threads
474,186
Messages
2,570,998
Members
47,587
Latest member
JohnetteTa

Latest Threads

Top