Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/sleeve/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#classifyObject

change a pharse (‘test it now’) or (“test_it_now”) to a classname (‘TestItNow’)



4
5
6
# File 'lib/sleeve/extensions/string.rb', line 4

def classify
  clean.split(' ').each { |word| word.capitalize! }.join('')
end

#cleanObject

clean a string of unwanted characters before we turn into a class or variable name



14
15
16
# File 'lib/sleeve/extensions/string.rb', line 14

def clean
  gsub(/[^\w\s\-\—]/,'').gsub(/[^\w]|[\_]/,' ').split.join(' ')  
end

#instantifyObject

change a phrase (‘testing now’) to an instance variable name (‘testing_now’)



9
10
11
# File 'lib/sleeve/extensions/string.rb', line 9

def instantify
  clean.gsub(/\s+/, '_').downcase
end