Created
May 4, 2013 22:10
-
-
Save satoyos/5518935 to your computer and use it in GitHub Desktop.
Class Template with PROPERTIES
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 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