AnApprentice
AnApprentice

Reputation: 110950

Rails - Method that returns true or false

I'm working to create a method that returns true or false, but it's return neither, what am I doing wrong?

In the controller:

valid_email_domain(email.to_s)

protected
  def valid_email_domain(emailAddy)
    reg = Regexp.new /#{User::INVALID_EMAILS.map{|a| Regexp.quote(a)}.join("|")}/
    Rails.logger.info 'REGEX TIME'
    Rails.logger.info emailAddy.scan(reg).size    
    if emailAddy.scan(reg).size == 0
      return true
    else
      return false
    end
  end

valid_email_domain isn't return anything. What's the issue? Thanks

Upvotes: 0

Views: 9490

Answers (1)

Jacob Relkin
Jacob Relkin

Reputation: 163228

Try this:

def valid_email_domain?(emailAddy)
   reg = Regexp.new /#{User::INVALID_EMAILS.map{|a| Regexp.quote(a)}.join("|")}/
   Rails.logger.info 'REGEX TIME'
   Rails.logger.info emailAddy.scan(reg).size    
   emailAddy.scan(reg).size == 0
end

As a side point, a common method naming convention in Ruby is to use a trailing ? for methods that return a boolean.

Upvotes: 2

Related Questions