ActiveRecord concerns make it very easy to add collections of code to ActiveRecord classes. In this example we see how adding two methods will be added to all ActiveRecord classes. 1) Add a file called ‘registration_hooks.rb’ to the lib/ directory of your Rails application. module RegistrationHooks extend ActiveSupport::Concern   def notify! # send email or trigger web hook end   module ClassMethods def count_opted_out # return a count of users who don’t wish to be notified end end end   # add this at the bottom of the file. It will be included. ActiveRecord::Base.send(:include, RegistrationHooks) :)

ActiveRecord is fairly simple to extract from the rails stack. In this example we can see how to create a DB table of users without all the overhead of Rails or Sinatra. require ‘rubygems’ require ‘fastercsv’ require ‘active_record’   # Set up AR connection and define User class   ActiveRecord::Base.establish_connection( :adapter => "postgres", :host => "localhost", :username => "brettu", :password => "********", :database => "clients" )   # This assumes we have a table set up already. class User set_table_name ‘user’ set_primary_key ‘userid’ end   FasterCSV.foreach(’email_list.csv’, headers: true) do |row| User.create! row.to_hash end :)