Created
July 26, 2016 07:25
-
-
Save kaochenlong/29ff3ff6b0ad1e6201083cfc74b648e3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class A | |
def self.my_attr_accessor(attr) | |
define_method "#{attr}" do | |
instance_variable_get("@#{attr}") | |
end | |
define_method "#{attr}=" do |param| | |
instance_variable_set("@#{attr}", param) | |
end | |
end | |
my_attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
end | |
a = A.new("kk") | |
puts a.name | |
a.name = "yy" | |
puts a.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment