From: Reacher Date: 2007-12-07T00:51:14+09:00 Subject: Re: regular expression. newbie problem. On Dec 6, 9:42 am, Johnathan Smith wrote: > Hi, > > i know this is a pretty basic problem but im a newbie so any help would > be greatly appreciated > > im trying to write a name class one which returns a first name a > surname, first and second initials > > however, i realise i regular expression is needed to go through the name > to produce the correct output. however im unsure of whaty regular > expression to use and whether my class is looking correct in general > > anyhelp would be greatly appreciated > > thanks > > name class: > > class Name > > def initialize(name) > @fname = name.slice!(rexesp) > @sname = name.slice!(regexp) > @mname = name.slice!(regexp) > > def firstname > return @fname > end > > def surname > return @sname > end > > def firstinitial > return @finitial > end > > def firstinitial > return @sinitial > end > -- > Posted viahttp://www.ruby-forum.com/. You can achieve this with ease by better utilizing Ruby's string functionality From irb: >> first_name = 'Osmosis' 'Osmosis' >> last_name = 'Jones' 'Jones' >> full_name = [first_name, last_name].join(' ') 'Osmosis Jones' >> short_name = [first_name, last_name.first].join(' ') 'Osmosis J' >> initials = [(first_name.first + '.'), (last_name.first + '.').join(' ') 'O. J.'