Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sbryant/110778 to your computer and use it in GitHub Desktop.
Save sbryant/110778 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'active_record'
module A
class B < ActiveRecord::Base
def self.a
self.name + ' -- ' + self.object_id.to_s
end
end
end
mods = ["T", "S", "R"]
mods.each do |mod|
_mod = Module.new do
A.constants.each do |con|
const_set(con, ("A::" + con).constantize.dup)
end
end
Kernel.eval "#{mod} = _mod"
end
puts A::B.a # A::B
puts T::B.a # T::B
puts S::B.a # S::B
puts R::B.a # R::B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment