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