Muhammad Faisal Iqbal Muhammad Faisal Iqbal - 2 years ago 69
Ruby Question

String comparison like "abcDEF" == "*DEF"

I am working on an rails app in which I need a comparison like:

url == "http://localhost:3000/admin/admin_login"

I am wondering that is there a way to compare like:

url == "*/admin/admin_login"

nwk nwk
Answer Source

You can use a regexp.

irb(main):001:0> url = "http://localhost:3000/admin/admin_login"
=> "http://localhost:3000/admin/admin_login"
irb(main):002:0> url =~ /admin\/admin_login$/
=> 22
irb(main):003:0> url =~ /foo\/something_else$/
=> nil
irb(main):004:0> "http://localhost:3000/admin/admin_login/bar" =~ /admin\/admin_login$/
=> nil
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download