Created
August 14, 2018 00:01
-
-
Save epidemian/24ff8ce55824012c3a810135f21448a3 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
module AttributeAccessor | |
def self.for(attr_name) | |
Module.new do | |
attr_accessor attr_name | |
end | |
end | |
end | |
class Book | |
include AttributeAccessor.for(:title) | |
def title | |
"#{super} + super works!" | |
end | |
end | |
book = Book.new | |
book.title = "Dynamic module with Module.new" | |
puts book.title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment