Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/testRubyWorkGem.rb
Instance Method Summary collapse
Instance Method Details
#check_len(str) ⇒ Object
23 24 25 |
# File 'lib/testRubyWorkGem.rb', line 23 def check_len(str) str.length == 0 end |
#palindrome? ⇒ Boolean
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/testRubyWorkGem.rb', line 3 def palindrome? str = self.dup str.gsub!(/\W/, '') str.downcase! correct = true len = str.length - 1 str.split(//).each do |i| if !correct break end if str[i] == str[len] len -= 1 else correct = false break end end correct end |
#valid_brackets? ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/testRubyWorkGem.rb', line 27 def valid_brackets? stack = [] self.split(//).each do |i| if i == '(' stack.append(i) else if i == ')' && !check_len(stack) stack.pop() elsif i == ')' && check_len(stack) stack.append(i) break end end end check_len(stack) end |