summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPaul Kmiec <[email protected]>2023-05-10 21:34:42 -0700
committerPaul Kmiec <[email protected]>2023-05-10 21:48:17 -0700
commit0c64b01f6c4c92f27dab2d0019d7bd133308854b (patch)
treea0f53a2242672ab5904a6a9e85dbceb0b43f67ac
parent1d94514b6562131371130449eaccf711aa60dc95 (diff)
downloadcaxlsx-0c64b01f6c4c92f27dab2d0019d7bd133308854b.tar.gz
caxlsx-0c64b01f6c4c92f27dab2d0019d7bd133308854b.zip
Fix `SimpleTypedList#to_a` and `SimpleTypedList#to_ary` returning the internal list instance
The `to_a` and `to_ary` now work more like standard Array methods with `to_a` returning a new array containing the elements of self and `to_ary` returning self.
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/axlsx/util/simple_typed_list.rb6
-rw-r--r--test/util/tc_simple_typed_list.rb11
3 files changed, 11 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 49cae46a..19f5d742 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@ CHANGELOG
- **Unreleased**: 4.0.0
- Drop support for Ruby versions < 2.6
- Added frozen string literals
+ - Fix `SimpleTypedList#to_a` and `SimpleTypedList#to_ary` returning the internal list instance
- **April.23.23**: 3.4.1
- [PR #209](https://github.com/caxlsx/caxlsx/pull/209) - Revert characters other than `=` being considered as formulas.
diff --git a/lib/axlsx/util/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb
index 0798ee22..c3910fca 100644
--- a/lib/axlsx/util/simple_typed_list.rb
+++ b/lib/axlsx/util/simple_typed_list.rb
@@ -84,12 +84,6 @@ module Axlsx
self
end
- def to_ary
- @list
- end
-
- alias :to_a :to_ary
-
# join operator
# @param [Array] v the array to join
# @raise [ArgumentError] if any of the values being joined are not
diff --git a/test/util/tc_simple_typed_list.rb b/test/util/tc_simple_typed_list.rb
index b62b5353..1a3d907b 100644
--- a/test/util/tc_simple_typed_list.rb
+++ b/test/util/tc_simple_typed_list.rb
@@ -82,7 +82,16 @@ class TestSimpleTypedList < Test::Unit::TestCase
@list.push 1
@list.push 2
- assert_equal([1, 2], @list.to_ary)
+ assert_equal([1, 2], @list)
+ end
+
+ def test_to_a
+ refute_equal(@list.object_id, @list.to_a.object_id)
+ assert_instance_of(Array, @list.to_a)
+ end
+
+ def test_to_ary
+ assert_equal(@list.object_id, @list.to_ary.object_id)
end
def test_insert