Created
July 27, 2012 08:33
-
-
Save codespectator/3186845 to your computer and use it in GitHub Desktop.
Revisions
-
James MacLeod revised this gist
Jul 27, 2012 . 1 changed file with 15 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,17 @@ validate :full_name_length def full_name [forename, surname].compact.join(' ') end def full_name=(full_name_str) name_arr = full_name_str.split(' ',2) self.forename = name_arr.first self.surname = name_arr.last end private def full_name_length errors.add(:full_name, 'is not correct') if full_name.split(' ',2).length != 2 end -
James MacLeod created this gist
Jul 27, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ def full_name=(full_name_str) name_arr = full_name_str.split(' ',2) if name_arr.length == 2 self.forename = name_arr.first self.surname = name_arr.last else errors.add :full_name, 'is not correct' end end