If statement in Ruby using Regex -


everything seems working fine except commented line:

#return false if not s[0].upcase =~ /az/ 

and fourth check.

what correct if statement s[0] , /az/ comparison?

def starts_with_consonant?(s)    return false if s.length == 0    #return false if not s[0].upcase =~ /az/    n = "aeiou"    m = s[0]    return true if not n.include? m.upcase    false  end   puts starts_with_consonant?("artyom") # false 1  puts starts_with_consonant?("rtyom")  # true 2  puts starts_with_consonant?("artyom") # false 3  puts starts_with_consonant?("$rtyom") # false 4  puts starts_with_consonant?("") # false 5 

try this...

def starts_with_consonant? s   /^[^aeiou\d\w]/i =~ s ? true : false end 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -