title: Railstutorial.org Chapter 8: digest method definition
body: <p>I'm currently working through Michael Hartl's Rails tutorial and I found a method definition I don't quite get: </p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
  
  before_save { self.email = email.downcase }
    validates :name,  presence: true, length: { maximum: 50 }
    VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
    validates :email, presence: true, length: { maximum: 255 },
                      format: { with: VALID_EMAIL_REGEX },
                      uniqueness: { case_sensitive: false }
    has_secure_password
    validates :password, presence: true, length: { minimum: 6 }
  
    # Returns the hash digest of the given string.
    def User.digest(string)
      cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
                                                    BCrypt::Engine.cost
      BCrypt::Password.create(string, cost: cost)
    end
  end
  </code></pre>
  
  <p>The crucial part is the definiton of <code>User.digest</code> ... why does he write <code>def User.digest(string)</code> and not just <code>def digest(string)</code> ... </p>
  
  <p>We are in the User class so every method in it should be accessible by <code>User.&lt;method_name&gt;</code>. So isn't it redundant or wrong to define a method like this?</p>