Skip to content

Instantly share code, notes, and snippets.

@nalabjp
Created March 8, 2017 16:50
Show Gist options
  • Save nalabjp/7cb208d502f62a939bb8256771bee847 to your computer and use it in GitHub Desktop.
Save nalabjp/7cb208d502f62a939bb8256771bee847 to your computer and use it in GitHub Desktop.
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