Skip to content

Commit 32c9053

Browse files
author
Derek Hower
committed
Make Person comparable
1 parent e22ae2b commit 32c9053

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/arch_obj_models/obj.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ def text
350350

351351
# Personal information about a contributor
352352
class Person
353+
include Comparable
354+
353355
# @return [String] Person's name
354356
def name = @data["name"]
355357

@@ -364,6 +366,12 @@ def company = @data["company"]
364366
def initialize(data)
365367
@data = data
366368
end
369+
370+
def <=>(other)
371+
raise ArgumentError, "Person is only comparable to Person (not #{other.class.name})" unless other.is_a?(Person)
372+
373+
name <=> other.name
374+
end
367375
end
368376

369377
# represents a JSON Schema compoisition, e.g.:

0 commit comments

Comments
 (0)