Ruby on Rails Thursday, February 5, 2015

is this fit for your purpose ?

def my_select(array,str)
  array.select{ |sub_array| %r(#{str})=~ sub_array.join}
end

def another_select(array,str)
  array.select{ |sub_array| %r(#{str})=~ sub_array.first.to_s}
end

my_array = [[1,2],[11,2],[23,89]]
while str = gets
  p my_select(my_array,str.chomp)
  p another_select(my_array,str.chomp)
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/23541c99-dfe6-4adc-abd1-afba92447488%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment