Created
March 8, 2017 16:50
-
-
Save nalabjp/7cb208d502f62a939bb8256771bee847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless File.exists?('./Gemfile') | |
File.write('./Gemfile', <<~GEMFILE) | |
source 'http://rubygems.org' | |
gem 'activesupport' | |
GEMFILE | |
system 'bundle install --path=vendor/bundle' | |
end | |
require 'bundler/setup' | |
require 'active_support' | |
class User | |
include ActiveSupport::Callbacks | |
define_callbacks :find | |
set_callback :find, :after, :run_after_find | |
def init_with | |
run_callbacks(:find) { puts 'init_with!!' } | |
end | |
def run_after_find | |
puts 'after find!!' | |
end | |
end | |
puts '---' | |
u1 = User.allocate | |
u1.init_with | |
puts '---' | |
u2 = User.allocate | |
u2.extend(Module.new { def run_after_find; end }) | |
u2.init_with | |
puts '---' | |
u3 = User.allocate | |
u3.init_with |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment