Names and stuff

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 ?

On Aug 11, 7:18 am, bingo bob [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs