Created
August 14, 2014 21:30
-
-
Save ferryzhou/8c296d62d7f773c4a8cd to your computer and use it in GitHub Desktop.
Ruby Class Initialize with Hash Arguments
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
def initialize(args = {}) | |
defaults = { | |
:file_list_cache_dir => 'cache/filelists/', | |
:img_root => 'cache/img/', | |
:sensor_res_img_root => 'cache/srimg/' | |
} | |
defaults.merge(args).each do |attr, val| | |
instance_variable_set("@#{attr}", val) if defaults.has_key?(attr) && (not val.nil?) | |
end if args | |
setup | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment