Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Programming (http://www.go4expert.com/forums/programming-forum/)
-   -   Ruby - Help with select method (http://www.go4expert.com/forums/ruby-help-select-method-t29716/)

Rofellos 3Jul2013 04:03

Ruby - Help with select method
 
Hi,

I have a problem in Ruby that I can't solve, I already tried to google it, but nothing.

I hava an array. I want to use the select method to select tthe elements that contains the string "YES" or the string "NO".

It doesn't work:

a.select { |x| x.include? "YES" || x.include? "NO" }

Can anyone help me?

Thanks!

pradeep 3Jul2013 11:23

Re: Ruby - Help with select method
 
This works :-)

Code: Ruby

#!/usr/bin/ruby

a = ["Pradeep","Yes","YES","NO"]

print a.select { |x| x.include?("YES") || x.include?("NO") }


Rofellos 3Jul2013 19:24

Re: Ruby - Help with select method
 
Thank you, it works!

It works only with the '(' and ')', and without the white space after 'include?'.


All times are GMT +5.5. The time now is 19:45.