Skip to content

Instantly share code, notes, and snippets.

@satoyos
Created May 4, 2013 22:10
Show Gist options
  • Select an option

  • Save satoyos/5518935 to your computer and use it in GitHub Desktop.

Select an option

Save satoyos/5518935 to your computer and use it in GitHub Desktop.
Class Template with PROPERTIES
class Book
PROPERTIES = [:title, :author, :year]
PROPERTIES.each do |prop|
attr_accessor "#{prop}".to_sym
end
def initialize(initial_hash={})
initial_hash.each do |key, value|
self.send("#{key}=", value) if PROPERTIES.member? key.to_sym
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment