Module: Boqwij::StringExtensions
- Defined in:
- lib/boqwij/string_extensions.rb
Overview
A set of extensions to the String class.
Instance Method Summary collapse
-
#capwords ⇒ Object
A method to capitalize the first letter of each word in a string.
-
#is_palindrome? ⇒ Boolean
A method to detect whether a given string is a palidrome.
-
#parens ⇒ Object
A method to wrap parenthese around a given string.
Instance Method Details
#capwords ⇒ Object
A method to capitalize the first letter of each word in a string.
5 6 7 8 9 10 11 12 |
# File 'lib/boqwij/string_extensions.rb', line 5 def capwords @words = self.split @revised = %w[] @words.each do |word| @revised << word.capitalize end @final = @revised.join(" ") end |
#is_palindrome? ⇒ Boolean
A method to detect whether a given string is a palidrome. (e.g., ‘civic’.is_palindrome? # => true)
21 22 23 24 25 26 |
# File 'lib/boqwij/string_extensions.rb', line 21 def is_palindrome? @original = self @backwards = @original.reverse return false if @original.casecmp(@backwards) != 0 true end |
#parens ⇒ Object
A method to wrap parenthese around a given string.
15 16 17 |
# File 'lib/boqwij/string_extensions.rb', line 15 def parens '(' + self.to_s() + ')' end |