Created
August 23, 2014 05:44
-
-
Save kisai/e4b22df97c9ad9125b86 to your computer and use it in GitHub Desktop.
My attr_accesor.rb
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
class Class | |
#firstly, the * decoration on the parameter variable | |
#indicates that the parameters should come in as an array | |
#of whatever was sent | |
def my_attr_accessor(*args) | |
#We simply iterate through each passed in argument... | |
args.each do |arg| | |
#Here's the getter | |
self.class_eval("def #{arg};@#{arg};end") | |
#Here's the setter | |
self.class_eval("def #{arg}=(val);@#{arg}=val;end") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment