Skip to content

Instantly share code, notes, and snippets.

@chad
Created March 18, 2009 19:10
Show Gist options
  • Save chad/81322 to your computer and use it in GitHub Desktop.
Save chad/81322 to your computer and use it in GitHub Desktop.
module ActiveSomething
class Base
def self.setup_methods!
columns = File.readlines("#{self.name}.schema").map do |line|
line.chomp.split(/:/)
end
columns.each do |name, column_type|
instance_eval{attr_accessor name}
end
end
end
end
# class Person < ActiveSomething::Base
# end
Dir['*.schema'].each do |file_name|
klass_name = file_name.sub(/\.schema$/, '')
Object.const_set(klass_name, Class.new(ActiveSomething::Base))
Object.const_get(klass_name).setup_methods!
end
person = Person.new
person.name=("Chad")
person.age = 21
puts person.name
puts person.age
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment