Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby - using include method in a case statement

Tags:

I'm using something like this:

case referer
      when (referer.include? "some_string")
        redirect_link = edit_product_path
      when (referer.include? "some_other_string")
        redirect_link = other_product_path
end

Unfortunately, this returns nil even if the string some_string is present in the variable referer.

Here's what i tried in Ruby Console:

ruby-1.8.7-p334 :006 > jasdeep = "RAILS"
ruby-1.8.7-p334 :026 > case jasdeep
ruby-1.8.7-p334 :027?>   when (jasdeep.include? "AI")
ruby-1.8.7-p334 :028?>   puts "Hello"
ruby-1.8.7-p334 :029?> end
=> nil

Any inputs will be appreciated.

like image 931
Jasdeep Singh Avatar asked May 22 '11 00:05

Jasdeep Singh


2 Answers

Try this

jasdeep = "RAILS"
case jasdeep
when /IL/
  puts "Hello"
end
like image 124
Aj Gu Avatar answered Oct 23 '22 05:10

Aj Gu


jasdeep = "RAILS"

case
  when jasdeep.include?("AI")
    puts "Hello"
end
like image 45
Vasiliy Ermolovich Avatar answered Oct 23 '22 06:10

Vasiliy Ermolovich