Skip to content

Instantly share code, notes, and snippets.

@acro5piano
Last active September 6, 2016 16:38
Show Gist options
  • Select an option

  • Save acro5piano/7620f6e394ef89727d1347e91f46ca2f to your computer and use it in GitHub Desktop.

Select an option

Save acro5piano/7620f6e394ef89727d1347e91f46ca2f to your computer and use it in GitHub Desktop.
has_secure_passwordでauthenticateメソッドが追加される仕組み ref: http://qiita.com/acro5piano/items/416c08a808c850e0477e
require_relative './secure_password'
class ActiveRecord
extend SecurePassword
end
class User < ActiveRecord::Base
has_secure_password
end
user = User.new
user.authenticate('password')
require_relative './user.rb'
user = User.new
puts user.authenticate
#=> true
class User < ActiveRecord
has_secure_password
def test
has_secure_password
end
end
user = User.new
puts user.authenticate
puts user.test
# => undefined method `has_secure_password'
# for #<User:0x0055b91a9f0280> NoMethodError
module SecurePassword
def has_secure_password
include SecurePassword::InstanceMethodsOnActivation
end
module InstanceMethodsOnActivation
def authenticate
true
end
end
end
require_relative './active_record'
class User < ActiveRecord
has_secure_password
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment