I taught myself Ruby for a specific problem that I am trying to solve. I notice that many people are using =~, and /\in your code. I'm not quite sure how they work, and just wanted to explain. For example, I looked at someones code for this Pig Latin translator, and this is the first time I see them being used.
def piglatin(word)
if word =~ (/\A[aeiou]/i)
word = word + 'ay'
elsif word =~ (/\A[^aeiou]/i)
match = /\A[^aeiou]/i.match(word)
word = match.post_match + match.to_s + 'ay'
end
word
end
I just got confused about the features /\and=~
source
share