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 9189453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:14:26+00:00 2026-06-17T20:14:26+00:00

I was reading Why’s poignant guide to ruby and came upon this module on

  • 0

I was reading Why’s poignant guide to ruby and came upon this module on chapter 5:

require 'endertromb'
module WishScanner

   def scan_for_a_wish

      wish = self.read.detect do |thought|
        thought.index( 'wish: ' ) == 0
      end

      wish.gsub( 'wish: ', '' )
   end
end

I have been trying to figure out how it works but what is confusing me is how thought.index( 'wish: ' ) == 0 and wish.gsub( 'wish: ', '' ) work. According to the author the purpose of this method is to “only pick up a wish if it starts with the word wish and a colon and a space. That way the planet doesn’t fill up with every less-than-ten-letter word that appears in people’s heads.”

But the way I understand it, thought.index( 'wish: ' ) == 0 will check if thought starts with 'wish: '. However i dont understand wish.gsub( 'wish: ', '' ) in the way I see it it seems to just substitute wish with an empty string.

Can any one offer any explanation or further insight into it?

Thank you in advance for any help.

  • 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-17T20:14:27+00:00Added an answer on June 17, 2026 at 8:14 pm

    wish.gsub( 'wish: ', '' ) in the way I see it it seems to just substitute wish with an empty string

    Exactly! It replaces the string "wish: " in a string like "wish: A pony!" with "".
    I.e. it turns “wish: A pony!” into “A pony!”.

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

Sidebar

Related Questions

reading the SCJP book, I've found something like this in the chapter 1 self-test
Reading through this , I came to the bit on default values for function
Reading the Scala by Example book and there is this example when Martin explains
Reading through this excellent article about safe construction techniques by Brain Goetz, I got
Reading the documentation I thought this code would write logs to a file in
Reading C++ Templates: The Complete Guide and it says Note that templates cannot be
Reading some topics I found this piece of code, and I'm wondering, how does
Reading about the lack of persistence ignorance in Entity Framework I often stumble upon
Reading through wikipedia I came across the concept of Sprints in Agile development. From
Reading along with the agile book, it says this in a footnote: ... You

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.