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

  • Home
  • SEARCH
  • 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 160981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:07:54+00:00 2026-05-11T11:07:54+00:00

I am still new to Ruby and basically just writing my first micro-program after

  • 0

I am still new to Ruby and basically just writing my first micro-program after finishing Cooper’s book. I was pointed to the direction of avoiding monkey patching but the problem is I don’t know what are the alternatives to achieve the same behavior. Basically, I want to add a new method that is accessible by every string object. The obvious monkey-patching way is to:

class String   def do_magic     ...magic...   end end 

I recall there’s a way using String.send. But I can’t remember how it’s done nor where I read it. Can anyone point out any alternatives that would still let me make that method available to the String class and child objects?

  • 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. 2026-05-11T11:07:54+00:00Added an answer on May 11, 2026 at 11:07 am

    Any other way of doing this would just be a more awkward syntax for monkey patching. There are ways involving send and eval and all sorts of things, but why? Go ahead and do it the obvious way.

    You want to be careful of monkey patching in big projects or when you have dependencies, because you can wind up with conflicts when several hands are all messing around in the same place. This doesn’t mean look for an alternative syntax that accomplishes the same thing — it means be careful when you’re making changes that could affect code that’s not yours. This probably isn’t a concern in your particular case. It’s just something that might need to be addressed in larger projects.

    One alternative in Ruby is that you can add methods to a single object.

    a = 'Hello' b = 'Goodbye' class <<a   def to_slang     'yo'   end end a.to_slang # => 'yo' b.to_slang # NoMethodError: undefined method `to_slang' for 'Goodbye':String 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer We have used SharpZipLib successfully on many projects. I know… May 11, 2026 at 5:41 pm
  • Editorial Team
    Editorial Team added an answer You only receive usage information if you somehow program the… May 11, 2026 at 5:41 pm
  • Editorial Team
    Editorial Team added an answer UITextField* f = [[UITextField alloc] init]; f.autocorrectionType = UITextAutocorrectionTypeNo; May 11, 2026 at 5:41 pm

Related Questions

I am still very new to Ruby (reading through the Pickaxe and spending most
Possible Duplicate: What does map(&:name) mean in Ruby? I was watching a railscast and
I am still new to sharepoint and would like to know if it is
I am still new to C# and I've been struggling with various issues on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.