Skip to content

Instantly share code, notes, and snippets.

@patmaddox
Created May 19, 2009 01:10
Show Gist options
  • Select an option

  • Save patmaddox/113851 to your computer and use it in GitHub Desktop.

Select an option

Save patmaddox/113851 to your computer and use it in GitHub Desktop.
class SimpleAR
def self.has_many(collection)
define_method(collection) do
var_name = "@#{collection}"
instance_variable_set(var_name, []) unless instance_variables.include?(var_name)
instance_variable_get var_name
end
end
end
class User < SimpleAR
has_many :blog_posts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment