From fe4506c4e9dbed226b653e625a0498dafbbe7281 Mon Sep 17 00:00:00 2001 From: David Runger Date: Tue, 16 Jun 2020 08:03:18 -0700 Subject: [PATCH] Rename Shaped::Shape#descriptor methods to #to_s This makes it easier to integrate into / be used by other gems, since it makes instances of `Shaped::Array` and `Shaped::Hash` more "class like" since now both classes and those `Shaped::Shape` classes can respond to that same `#to_s` method. --- CHANGELOG.md | 4 ++++ lib/shaped/array.rb | 2 +- lib/shaped/expected_class_descriptions.rb | 2 +- lib/shaped/hash.rb | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5e0662..27c9887 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased +### Changed +- Rename `Shaped::Array#descriptor` and `Shaped::Hash#descriptor` methods to `#to_s` + ## 0.2.0 - 2020-06-16 ### Added - Add `Shaped::Array` method and class diff --git a/lib/shaped/array.rb b/lib/shaped/array.rb index 919de00..b37b0df 100644 --- a/lib/shaped/array.rb +++ b/lib/shaped/array.rb @@ -22,7 +22,7 @@ def initialize(shape_description) @match_failure_reasons = {} end - def descriptor + def to_s "Array shaped like [#{@shape_klass}]" end diff --git a/lib/shaped/expected_class_descriptions.rb b/lib/shaped/expected_class_descriptions.rb index d941d74..675b620 100644 --- a/lib/shaped/expected_class_descriptions.rb +++ b/lib/shaped/expected_class_descriptions.rb @@ -5,7 +5,7 @@ module Shaped::ExpectedClassDescriptions def expected_class_descriptor(expected_klass) if expected_klass.is_a?(Shaped::Shape) - expected_klass.descriptor + expected_klass.to_s else expected_klass.name end diff --git a/lib/shaped/hash.rb b/lib/shaped/hash.rb index 67dc5bf..21bbc81 100644 --- a/lib/shaped/hash.rb +++ b/lib/shaped/hash.rb @@ -15,7 +15,7 @@ def initialize(shape_description) @match_failure_reasons = {} end - def descriptor + def to_s printable_shape_description = @shape_description.map do |key, value| "#{key.inspect} => #{expected_class_descriptor(value)}"