Module: Boqwij::StringExtensions

Defined in:
lib/boqwij/string_extensions.rb

Overview

A set of extensions to the String class.

Instance Method Summary collapse

Instance Method Details

#capwordsObject

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)

Returns:

  • (Boolean)


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

#parensObject

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