Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:17:18+00:00 2026-06-15T23:17:18+00:00

I was stuck on a problem, and a friend sent me a solution without

  • 0

I was stuck on a problem, and a friend sent me a solution without time to explain such. I’d like to come back to this problem and learn a little more from it. I was just wondering if someone could help me with a quick run down of specific aspects of this code.

def translate phrase
  phrase.split.map do |word|
    word =~ /^([^aeiouyq]*(qu)?)(.*)$/

    first_translation = $1
    rest_of_translation = $3

    "#{rest_of_translation}#{first_translation}ay"

   end.join(" ")
end

I don’t quite grasp the concept of how I substituted letters. The line I’m referring to is words =~

Related to this, I know $ refers to the chunks of my expression. Yet, I’m not quite sure I know how I obtained them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:17:19+00:00Added an answer on June 15, 2026 at 11:17 pm

    This is a simple Pig Latin translator. The code works in several steps:

    a = "this is a phrase".split
    => ["this", "is", "a", "phrase"] 
    b = a.map {|w| w =~ /^([^aeiouyq]*(qu)?)(.*)$/; [$1, $3] }
    => [["th", "is"], ["", "is"], ["", "a"], ["phr", "ase"]] 
    c = b.map {|v1,v2| "#{v2}#{v1}ay" }
    => ["isthay", "isay", "aay", "asephray"] 
    c.join(" ")
    => "isthay isay aay asephray" 
    

    IRB is very helpful for analyzing snippets of code like this.

    The $1, $2, $3, etc. variables are special global variables that capture matches in parentheses in the regular expression. They don’t necessarily stick around for very long, so if you use them you should assign them to something else right away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a puzzle contest with my friends, and I'm stuck on this problem:
I got stuck in this problem for an hour. I am thinking this is
I got stuck with this problem. I wrap two tables inside of a h:form.
I am stuck with this problem for 3 days with no avail to solve
I am having a problem with friend functions. I figure this is the only
It's feel like I'm stuck, my friends. Can somebody explain me pick equations from
This is a problem I used to have all the time with the serial
One of my friends raised this problem to me. I was stuck because I
I've stuck at this problem. Our old-old programmers have encoded their CFM file based
I am having a hard time finding a simple solution to this. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.