Created
July 6, 2016 02:14
-
-
Save kaochenlong/88719a8fde9914c6ea82c83991a368e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Base | |
def self.has_one(something) | |
define_method "#{something}=".to_sym do |new_value| | |
instance_variable_set("@#{something}", new_value) | |
end | |
define_method something.to_sym do | |
instance_variable_get("@#{something}") | |
end | |
end | |
end | |
end | |
class Product < ActiveRecord::Base | |
has_one :user | |
end | |
p1 = Product.new | |
p1.user = "123" | |
puts p1.user #=> 123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment