From b868e636b207bf1243002b3b97821fef0b6dfff8 Mon Sep 17 00:00:00 2001 From: chopraanmol1 Date: Wed, 26 Dec 2018 11:26:07 +0530 Subject: [PATCH] Fix ruby instance variable not initialized warning --- lib/roo/excelx/cell/base.rb | 2 +- lib/roo/helpers/weak_instance_cache.rb | 2 +- test/excelx/cell/test_attr_reader_default.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/roo/excelx/cell/base.rb b/lib/roo/excelx/cell/base.rb index 9e2cc7ee..51fc75fb 100644 --- a/lib/roo/excelx/cell/base.rb +++ b/lib/roo/excelx/cell/base.rb @@ -58,7 +58,7 @@ def type end def formula? - !!@formula + !!(defined?(@formula) && @formula) end def link? diff --git a/lib/roo/helpers/weak_instance_cache.rb b/lib/roo/helpers/weak_instance_cache.rb index c50c7c58..96c026a2 100644 --- a/lib/roo/helpers/weak_instance_cache.rb +++ b/lib/roo/helpers/weak_instance_cache.rb @@ -10,7 +10,7 @@ module WeakInstanceCache def instance_cache(key) object = nil - if (ref = instance_variable_get(key)) && ref.weakref_alive? + if instance_variable_defined?(key) && (ref = instance_variable_get(key)) && ref.weakref_alive? begin object = ref.__getobj__ rescue => e diff --git a/test/excelx/cell/test_attr_reader_default.rb b/test/excelx/cell/test_attr_reader_default.rb index 03b1cbfc..c1ae2775 100644 --- a/test/excelx/cell/test_attr_reader_default.rb +++ b/test/excelx/cell/test_attr_reader_default.rb @@ -57,7 +57,7 @@ def test_cell_default_values def assert_values(object, value_hash) value_hash.each do |attr_name, expected_value| value = if attr_name.to_s.include?("@") - object.instance_variable_get(attr_name) + object.instance_variable_defined?(attr_name) ? object.instance_variable_get(attr_name) : nil else object.public_send(attr_name) end