I saw
word =~/^qu/
in a program, what does it do:?
I saw
word =~/^qu/
in a program, what does it do:?
might as well show the whole method
def first_vowel(word)
if word =~/^qu/
2
else
word.gsub(/[aeiou].*$/, ‘’).size
end
end
Any ideas as I’m lost om what its even doling?
~= is the ruby match operator.
It matches a string to a regular expression.
e.g.
'Pullo' =~ /o/
# => 4
If there is no match, it will return nil.
As for the method you posted:
def first_vowel(word)
if word =~/^qu/
2
else
word.gsub(/[aeiou].*$/, '').size
end
end
it checks to see if the word it receives as an argument starts with a “qu”.
If so, it returns 2
Otherwise it replaces everything after (and including) the occurrence of the first vowel, then returns the size of what’s left.
thanks
This is the best and only answer.
Closing the thread.