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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:00:52+00:00 2026-05-30T20:00:52+00:00

look the demo code: class A def method_a puts this is method_a end end

  • 0

look the demo code:

class A
  def method_a
    puts "this is method_a"
  end
end

class B < A
  def self.hide_method name
    if instance_methods.include? name
      @hidden_mthod ||= {}
      @hidden_mthod[name] = instance_method name
      undef_method name
    end
  end

  def self.invoke_hidden_methods
    puts @hidden_mthod.inspect
  end

  def bound_method name
    self.class.class_variable_get(:@hidden_mthod)[name].bind(self)
  end
end

b = B.new
b.method_a
B.hide_method :method_a
B.invoke_hidden_methods

b.bound_method :method_a  **#error**

b.method_a **#error**

The thing i want to do is rebind special method to the instance.but how can i access @hidden_method which defined in class with instance method?

UPDATED:
Thanks,Boris Strandjev, Ur really a nice man. as you above-mentioned, I think the code should be more simplified like this:

def bound_method name
  method_body = self.class.instance_variable_get(:@hidden_method)[name]
  self.class.send :define_method, name, method_body
end
  • 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-30T20:00:54+00:00Added an answer on May 30, 2026 at 8:00 pm

    Change your bound_method to:

    def bound_method name
        self.class.instance_variable_get(:@hidden_mthod)[name].bind(self)
    end
    

    This is instance variable, not class.

    EDIT As per your comment I did not solve your problem. So I had to rust off a lot of ancient ruby knowledge. I found this thread.

    And then I changed your method further:

    def bound_method name
      puts self.class.instance_variable_get(:@hidden_mthod)[name]
      metaclass = class << self; self; end
      metaclass.send(:define_method, name,
                 self.class.instance_variable_get(:@hidden_mthod)[name])
    end
    

    Basically bind will allow you to call this method on the instance once like:

    self.class.instance_variable_get(:@hidden_mthod)[name].bind(self).call()
    

    But does not add the method to the instance. :define_method does. Hopefully this will help you.

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

Sidebar

Related Questions

Please have a look at this demo page that I cooked up a while
Take a look at this example: http://www.extjs.com/deploy/dev/examples/multiselect/multiselect-demo.html On it, there are components rendered against
look at this code, <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <script> function change() {
Look please below this codes throw me : FormatException was unhandled by user code
Let's look at the following code snippet in Java. package demo; import java.util.Calendar; final
please take a look of this, the file demo.php is an example of the
I am trying to integrate the code from this demo: http://code.google.com/p/gwt-spring-starter-app/ into my main
I have a code which look something like this. When trying to do a
Look at this image: alt text http://img139.imageshack.us/img139/4488/picture2ep3.png I know how to add UITableView with
Look at this situation: www.websitea.com displays an img tag with a src attribute of

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.