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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:46:36+00:00 2026-05-14T18:46:36+00:00

@string = Sometimes some stupid people say some stupid words @string.enclose_in_brackets(some) # => Sometimes

  • 0
@string = "Sometimes some stupid people say some stupid words"

@string.enclose_in_brackets("some") # => "Sometimes {some} stupid people say {some} stupid words"

How should the method enclose_in_brackets look ? Please keep in mind, I want only enclose whole words, (I don’t want “{Some}times {some} stupid….”, the “sometimes” word should be left unchanged

  • 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-05-14T18:46:36+00:00Added an answer on May 14, 2026 at 6:46 pm

    It’s just a string substitution using a regular expression. You can use the word boundary special character to prevent it from matching your parameter when it’s in the middle of another word. And put your method inside the String class so that you can call it directly on a string like in your example.

    class String
      def enclose_in_brackets(selection)
        self.gsub(/(\b#{selection}\b)/i, '{\1}')
      end
    end
    
    'Sometimes some stupid people say some stupid words'.enclose_in_brackets('some')
    # Sometimes {some} stupid people say {some} stupid words.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

string.Format() with it's bla {0} bla syntax is great. But sometimes I don't want
I have some functions calling for user input, sometimes string, int or whatever. so
Sometimes I need to set some string values from code, for example: Page.Title =
I have a form that sometimes gets linked to with some query string parameters.
I have a Ruby string that can sometimes contain some non-printable characters. Before I
When people are posting some text on my website, they will sometimes insert a
Sometimes I need to find some strings inside DB usually it is just host-name
I have a Perl script, that's supposed to match this string: Sometimes, he says
Has anyone ever run into this issue before? Sometimes the string displays, sometimes half
Sometimes i face the following problem : string txt = con.Request.Params[Par_name].ToString();//the original par value

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.