开发者

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)

protecte开发者_开发知识库d
  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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜