Skip to content

Instantly share code, notes, and snippets.

@epidemian
Created August 14, 2018 00:01
Show Gist options
  • Save epidemian/24ff8ce55824012c3a810135f21448a3 to your computer and use it in GitHub Desktop.
Save epidemian/24ff8ce55824012c3a810135f21448a3 to your computer and use it in GitHub Desktop.
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