From c17ce2d1cd6b824b7e86d3adcbd32ac5fb1e002b Mon Sep 17 00:00:00 2001 From: Sankha Narayan Guria Date: Thu, 5 Apr 2018 01:58:11 -0400 Subject: [PATCH] UUID implements inspect (#5574) --- spec/std/uuid_spec.cr | 5 +++++ src/uuid.cr | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/spec/std/uuid_spec.cr b/spec/std/uuid_spec.cr index 1e8a54dfa7e0..ce0061f6a5bb 100644 --- a/spec/std/uuid_spec.cr +++ b/spec/std/uuid_spec.cr @@ -9,6 +9,11 @@ describe "UUID" do subject.version.should eq UUID::Version::V4 end + it "does inspect" do + subject = UUID.random + subject.inspect.should eq "UUID(#{subject})" + end + it "works with variant" do subject = UUID.random(variant: UUID::Variant::NCS) subject.variant.should eq UUID::Variant::NCS diff --git a/src/uuid.cr b/src/uuid.cr index c859082b136f..c557b7935d2b 100644 --- a/src/uuid.cr +++ b/src/uuid.cr @@ -164,6 +164,13 @@ struct UUID to_slice == other.to_slice end + # Convert to `String` in literal format. + def inspect(io : IO) + io << "UUID(" + to_s(io) + io << ')' + end + def to_s(io : IO) slice = to_slice