Skip to content

Instantly share code, notes, and snippets.

View varyonic's full-sized avatar

Piers Chambers varyonic

View GitHub Profile
@varyonic
varyonic / inflector_extensions.rb
Created August 21, 2014 20:51
makes titleize respect hypens
# inspired by https://gist.github.com/zachrose/7549941
module ActiveSupport::Inflector
def nice_title(phrase)
return phrase if phrase =~ /^-+$/
phrase.split('-').map { |part|
if part.chars.count == part.bytes.count
part.titleize
else
part.split(' ').map { |word| word.mb_chars.titleize }.join(' ')