Skip to content

Commit

Permalink
UUID implements inspect (crystal-lang#5574)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngsankha authored and ysbaddaden committed Apr 5, 2018
1 parent 106d44d commit c17ce2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/std/uuid_spec.cr
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/uuid.cr
Expand Up @@ -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

Expand Down

0 comments on commit c17ce2d

Please sign in to comment.