Sha256: 9ac58a0660a2891d59d4bc9b021fdeedb534ee28bfe327fa9fbe2fb28434d49e

Contents?: true

Size: 500 Bytes

Versions: 8

Compression:

Stored size: 500 Bytes

Contents

# 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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
roo-2.10.1 lib/roo/helpers/default_attr_reader.rb
roo-2.10.0 lib/roo/helpers/default_attr_reader.rb
roo-2.9.0 lib/roo/helpers/default_attr_reader.rb
ruh-roo-3.0.1 lib/roo/helpers/default_attr_reader.rb
roo-2.8.3 lib/roo/helpers/default_attr_reader.rb
roo-2.8.2 lib/roo/helpers/default_attr_reader.rb
roo-2.8.1 lib/roo/helpers/default_attr_reader.rb
roo-2.8.0 lib/roo/helpers/default_attr_reader.rb