diff options
| author | 2019-01-14 01:40:56 -0500 | |
|---|---|---|
| committer | 2019-01-14 01:40:56 -0500 | |
| commit | dddfa903d2b856146f05ffb4415c31d6127bb5bf (patch) | |
| tree | e38c2aca92b54f06ccd0185f48dc47e3e1b3d77e /lib/roo/helpers/default_attr_reader.rb | |
| parent | 8280a21a23d44aa90177e2bc041d0b8dc8556f4b (diff) | |
New upstream version 2.8.0upstream/2.8.0
Diffstat (limited to 'lib/roo/helpers/default_attr_reader.rb')
| -rw-r--r-- | lib/roo/helpers/default_attr_reader.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/roo/helpers/default_attr_reader.rb b/lib/roo/helpers/default_attr_reader.rb new file mode 100644 index 0000000..a02ba84 --- /dev/null +++ b/lib/roo/helpers/default_attr_reader.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Roo + module Helpers + module DefaultAttrReader + def attr_reader_with_default(attr_hash) + attr_hash.each do |attr_name, default_value| + instance_variable = :"@#{attr_name}" + define_method attr_name do + if instance_variable_defined? instance_variable + instance_variable_get instance_variable + else + default_value + end + end + end + end + end + end +end |
