Class: String

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

Instance Method Summary collapse

Instance Method Details

#middle_with?(str) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/oh_my_method/string.rb', line 6

def middle_with?(str)
  (self =~ /.+#{str}.+/)? true : false
end

#palindrome?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/oh_my_method/string.rb', line 2

def palindrome?
  self == self.reverse
end

#sum_digitObject



10
11
12
# File 'lib/oh_my_method/string.rb', line 10

def sum_digit
  self.chars.map(&:to_i).inject(:+)
end