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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:45:05+00:00 2026-06-04T14:45:05+00:00

def a_method p in distress end alias :hero :a_method def a_method hero p Saved

  • 0
def a_method
  p "in distress"
end

alias :hero :a_method
def a_method
  hero
  p "Saved by the hero"
end

Here is a method in distress and it has been saved by a hero. But someone else doesn’t like how the story ends and decides to overwrite what the hero did.

alias :nemesis ?
def ?
   #which method to call?
   p "Captured by the nemesis"
end

Is it possible for the nemesis to overwrite what the hero did and have the final outcome be

"in distress"
"Captured by the nemesis"
  • 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-04T14:45:05+00:00Added an answer on June 4, 2026 at 2:45 pm

    It seems like this would work without any more aliasing:

    def a_method
      hero
      p "Captured by the nemesis"
    end
    

    There isn’t any way for the nemesis to “unalias” and determine the old value of :a_method before the hero came along, however. The fact that Ruby doesn’t preserve history like that is the reason you need aliases in such override situations in the first place.

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

Sidebar

Related Questions

Given that a function a_method has been defined like def a_method(arg1, arg2): pass Starting
I have a method defined in ApplicationController : def some_checking ... end And I
Say, I have the following 2 classes: class A def a_method end end class
In ruby you can do something like this: def method(a, b) ... end myMethod(*myArray)
Right now my code works as such: def method_a self.method_b ==> 'method_b' end def
def test_method [a, b, c].map {|i| yield(i) } end If I call test_method like
I have a method which calls a method on an integer: def print_time(time =
I have a method which calls for a classmethod of another class def get_interface_params_by_mac(self,
I need a method to get the data from an external editor. def _get_content():
Let's say that I have a method that looks like this: def raise_if_client_status_error(xml_resp) #

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.