From 5ef52158b6326f4d6c23031a81b8ab2d8e0b0d97 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Thu, 5 Dec 2024 11:04:58 +0100 Subject: [PATCH] Add Net::SMTP::Address#to_str Add implicit conversion from Net::SMTP::Address to String. Test both explicit and implicit conversion from Net::SMTP::Address to String. --- lib/net/smtp.rb | 1 + test/net/smtp/test_smtp.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb index 13e1f1f..639c01e 100644 --- a/lib/net/smtp.rb +++ b/lib/net/smtp.rb @@ -1152,6 +1152,7 @@ def initialize(address, *args, **kw_args) def to_s @address end + alias to_str to_s end end # class SMTP diff --git a/test/net/smtp/test_smtp.rb b/test/net/smtp/test_smtp.rb index 9a0ac53..2e29719 100644 --- a/test/net/smtp/test_smtp.rb +++ b/test/net/smtp/test_smtp.rb @@ -102,6 +102,8 @@ def test_rcptto_with_address def test_address a = Net::SMTP::Address.new('foo@example.com', 'p0=123', {p1: 456}, p2: nil, p3: '789') assert_equal 'foo@example.com', a.address + assert_equal '', "<#{a}>" # Address#to_s + assert_match(/\Afoo@example\.com\z/, a) # Address#to_str assert_equal ['p0=123', 'p1=456', 'p2', 'p3=789'], a.parameters end