Created
August 29, 2013 12:44
-
-
Save lidi/6377589 to your computer and use it in GitHub Desktop.
This file contains 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 characters
def title_case(title, options = {}) | |
return title if title.empty? | |
head, *tail = title.split(' ') | |
head.capitalize! << ' ' << tail.collect { |x| options[:minors] && options[:minors].downcase.split(' ').include?(x) ? x : x.capitalize! }.join(' ') | |
end | |
===================== | |
TESTS | |
Test.expect(title_case('the quick brown fox') == 'The Quick Brown Fox') | |
Test.expect(title_case('a clash of KINGS', minors: 'a an the OF') == 'A Clash of Kings') | |
Test.expect(title_case('') == '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If fact I might have overreacted with hash as optional parameter, so I've rewrote it:
def title_case(title, options = '')
return title if title.empty?
head, *tail = title.split(' ')
head.capitalize! << ' ' << tail.collect { |x| !options.empty? && options.downcase.split(' ').include?(x.downcase) ? x : x.capitalize! }.join(' ')
end
Tests are still passing but I get the same error when trying to submit