ruby - Rails regex with include -


i'm finding mx records based on user's email determine if use gmail. mx server records come this:

aspmx.l.google.com alt1.aspmx.l.google.com alt2.aspmx.l.google.com aspmx2.googlemail.com aspmx3.googlemail.com alt4.gmail-smtp-in.l.google.com alt3.gmail-smtp-in.l.google.com alt2.gmail-smtp-in.l.google.com gmail-smtp-in.l.google.com alt1.gmail-smtp-in.l.google.com 

where non google mail servers send stuff like:

mx2.emailsrvr.com mx1.emailsrvr.com nil 

what way determine if 1 of mx records contain google mx record. i've been trying:

  if mx.any? {|server| server.exchange.to_s.include? "google"}     return true   end 

this doesn't work requires match. elegant ideas? thanks

assuming mx array:

mx.any? { |server| server.exchange.to_s.downcase.include? "google" } 

should work. aside, because any? method returns true or false don't need explicitly return true, return value of any? method.

example:

[   "aspmx.l.google.com",    "alt1.aspmx.l.google.com",    "alt2.aspmx.l.google.com",    "aspmx2.googlemail.com",    "aspmx3.googlemail.com",    "alt4.gmail-smtp-in.l.google.com",    "alt3.gmail-smtp-in.l.google.com",    "alt2.gmail-smtp-in.l.google.com",    "gmail-smtp-in.l.google.com",    "alt1.gmail-smtp-in.l.google.com"  ] array.any? { |server| server.include? "google" } # => true array.any? { |server| server.downcase.include? "google" } # => true array.all? { |server| server.include? "google" } # => false array.all? { |server| server.downcase.include? "google" } # => true 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -