Created
March 9, 2014 02:50
-
-
Save codeprimate/9442248 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 FooStruct | |
def initialize(attrs) | |
# Create a Singleton Class (Anonymous Class) inheriting from FooStruct | |
klass = ( class << self; self; end ) | |
# Loop through the attributes | |
attrs.each do |attr| | |
# Within the context of the anonymous class... | |
klass.class_eval do | |
# Define accessors for each of the attributes | |
attr_accessor attr.to_sym | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment