On 05 May 2005, at 16:45, Logan Capaldo wrote:
> On 5/5/05, Chris Roos <> wrote:
>> I have a Person with title, forename and surname (all of which are
>> optional). I want to return a 'pretty' name for this person in the
>> format..
>>
>> title + <space> + forename + <space> + surname
>>
>> ..where any extraneous spaces are removed.
>
> "#{title} #{forename} #{surname}".strip
This leaves spaces in the middle.
[title, forename, surname].join(' ').gsub(/ /, ' ')
require 'test/unit'
class TestFullName < Test::Unit::TestCase
def setup
@title = "Mr."
@surname = "Hodel"
end
def test_strip
assert_equal "Mr. Hodel", "#{@title} #{@forename} #{@surname}".strip
end
def test_join_gsub
assert_equal("Mr. Hodel",
[@title, @forename, @surname].join(' ').gsub(/ /, '
'))
end
end
--
Eric Hodel -
-
http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04