Ruby on Rails Wednesday, August 11, 2010

On Aug 11, 7:18 am, bingo bob <li...@ruby-forum.com> wrote:
> 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.

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

> 2) 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
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment