Module: Roo::Helpers::DefaultAttrReader

Included in:
Excelx::Cell::Base
Defined in:
lib/roo/helpers/default_attr_reader.rb

Instance Method Summary collapse

Instance Method Details

#attr_reader_with_default(attr_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/roo/helpers/default_attr_reader.rb', line 6

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