# Names and stuff

**URL:** <https://www.ruby-forum.com/t/names-and-stuff/193107>\
**Category:** Rails\
**Created:** [August 11, 2010, 1:18pm UTC](https://www.ruby-forum.com/t/names-and-stuff/193107 "2010-08-11T13:18:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [August 11, 2010, 1:18pm UTC](https://www.ruby-forum.com/t/names-and-stuff/193107/1 "2010-08-11T13:18:53Z")

</div>

I’m trying to stuff like this in my BabyName model…

before\_save :capitalize

def capitalize  
self.title = title.capitalize  
self.forename = forename.capitalize  
self.surname = surname.capitalize  
self.middlenames = middlenames.split.each { |x| print  
x.capitalize!, " “}.join(” ")  
end

def full\_name  
self.title + " " + self.forename + " " + self.middlenames + " " +  
self.surname  
end

def initials

end

# 

two things;

1. my full\_name method doens’t seem great in that I might get two spaces  
between names.
2. how do I grab the initials method ?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [August 11, 2010, 4:00pm UTC](https://www.ruby-forum.com/t/names-and-stuff/193107/2 "2010-08-11T16:00:25Z")

</div>

On Aug 11, 7:18 am, bingo bob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> # 
> 
> two things;
> 
> 1. my full\_name method doens’t seem great in that I might get two spaces  
> between names.

You could build an array with all the components, remove any blanks or  
nils and then use join on all that

> 1. how do I grab the initials method ?

as in how to write it ? forename & surname should be straightforward,  
for middlenames you could just split on spaces and then take the first  
letter of each component

Fred
