I've been teaching myself Ruby and for a certain problem I'm trying to solve I notice a lot of people are using =~
and /\
in their code. I'm not really sure how they work and would just like an explanation. For example I was looking at someones code for this Pig Latin translator and this is the first time I'm seeing these 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'm just confused about the /\
slashes and the =~