From 7a177d693e27afbb734f053004dadf2412f91dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 12 Sep 2013 00:29:27 +0200 Subject: [PATCH 1/2] Fix a typo that broke all handling for negative numbers Sometimes, just sometimes, a man's gotta deal with both years and centuries BC in one piece of code. --- lib/roman.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/roman.rb b/lib/roman.rb index 1e13166..e7adbfb 100644 --- a/lib/roman.rb +++ b/lib/roman.rb @@ -33,7 +33,7 @@ class RomanNumeral < Numeric # def self.from_integer(int) #return nil if integer > MAX - return "-#{(-int).roman}" if int < 0 + return "-#{(-int).to_roman}" if int < 0 return "" if int == 0 ROMAN_VALUES_ASSOC.each do |(i, v)| return(i + from_integer(int-v)) if v <= int From 0a891c5c79f42e4d17550bcc069c6d729bd9ffce Mon Sep 17 00:00:00 2001 From: Thomas Sawyer Date: Tue, 24 Nov 2026 22:49:59 -0500 Subject: [PATCH 2/2] Test negative numbers; version 0.3.1 Co-Authored-By: Claude Fable 5.2 --- HISTORY.md | 8 ++++++++ roman.gemspec | 2 +- test/roman_case.rb | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index a698d90..e028da4 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,14 @@ # RELEASE HISTORY +## Unreleased (0.3.1) + +Changes: + +* Fix negative numbers, which raised NoMethodError when converted to a + string: `(-4).to_roman.to_s` is now `-IV`. (Bartosz DziewoƄski, #1) + + ## 0.3.0 / 2026-04-02 Maintenance release. Modernized project tooling. diff --git a/roman.gemspec b/roman.gemspec index 01897b5..78dce55 100644 --- a/roman.gemspec +++ b/roman.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'roman' - s.version = '0.3.0' + s.version = '0.3.1' s.summary = 'Real Roman Numerals' s.description = 'RomanNumeral class for working with roman numerals in a native form.' diff --git a/test/roman_case.rb b/test/roman_case.rb index cc0cb7a..dcdba90 100644 --- a/test/roman_case.rb +++ b/test/roman_case.rb @@ -55,5 +55,17 @@ end end + Method :to_s do + test "negative numbers" do + (-1).to_roman.to_s.assert == '-I' + (-4).to_roman.to_s.assert == '-IV' + (-1994).to_roman.to_s.assert == '-MCMXCIV' + end + + test "a result below zero" do + (4.to_roman - 10).to_s.assert == '-VI' + end + end + end