Skip to content

Instantly share code, notes, and snippets.

@Spaceghost
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spaceghost/9654301 to your computer and use it in GitHub Desktop.
Save Spaceghost/9654301 to your computer and use it in GitHub Desktop.
class Foo
ATTRIBUTES = %i|name address|
attr_reader *ATTRIBUTES
def initialize(opts={})
opts.keys.each do |meth|
self.send("#{meth}=", opts.fetch(meth, nil) # Do any special things here, I suppose
end
end
private
attr_writer *ATTRIBUTES.map {|attr| "#{attr}=".to_sym }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment