Jas*_*ngh 19 ruby ruby-on-rails case switch-statement
我正在使用这样的东西:
case referer
when (referer.include? "some_string")
redirect_link = edit_product_path
when (referer.include? "some_other_string")
redirect_link = other_product_path
end
Run Code Online (Sandbox Code Playgroud)
不幸的是,即使字符串some_string
存在于变量中,它也会返回nil referer
.
这是我在Ruby控制台中尝试的内容:
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
Run Code Online (Sandbox Code Playgroud)
任何输入将不胜感激.
Aja*_*nda 34
试试这个
jasdeep = "RAILS"
case jasdeep
when /IL/
puts "Hello"
end
Run Code Online (Sandbox Code Playgroud)