Forum: Ruby Code Tunning

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A4623da5f236a65ee4b8fce214de572b?d=identicon&s=25 Fernando Giannetti (rengojava)
on 2008-12-02 20:23
Hi!
there is a better way to do that?

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

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


Thanks!
05be5d6610e2c3f1780aa0e39e902e93?d=identicon&s=25 Farrel Lifson (Guest)
on 2008-12-02 20:37
(Received via mailing list)
2008/12/2 Fernando Giannetti <fgiannetti@gmail.com>:
> 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
---
Aimred - Ruby Development and Consulting
http://www.aimred.com
A4623da5f236a65ee4b8fce214de572b?d=identicon&s=25 Fernando Giannetti (rengojava)
on 2008-12-02 20:49
Farrel Lifson wrote:
>   state = anArray.include?(id) ? 'YES' : 'NO'

Oh! Im an idiot!
Thanks a lot!!!
This topic is locked and can not be replied to.