Skip to content

Instantly share code, notes, and snippets.

@ferryzhou
Created August 14, 2014 21:30
Show Gist options
  • Save ferryzhou/8c296d62d7f773c4a8cd to your computer and use it in GitHub Desktop.
Save ferryzhou/8c296d62d7f773c4a8cd to your computer and use it in GitHub Desktop.
Ruby Class Initialize with Hash Arguments
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