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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:40:43+00:00 2026-06-11T05:40:43+00:00

Is there a way to get a true proc from a method in Ruby?

  • 0

Is there a way to get a true proc from a method in Ruby?

An UnboundMethod obtained via instance_method does not fit the bill because I can only bind it to an object of the class that declared the method. I can’t reinterpret self inside the method body the way I could in a proc (using instance_exec).

Similarly, a Method obtained via method is not okay, because self is bound to the receiver of method and I cannot change it.

Edit (Clarification):

What I’m trying to do is to take a method defined in one class and transfer it to another class. This means I need to be able to reinterpret the meaning of self within the method. For procs, this is possible via instance_exec and instance_eval, but not for methods.

Why I am trying to move methods from one class to another? Long story short, to implement a form of namespacing, as I am most displeased with the visibility control provided by Ruby (there is no way to hide a module member to an including class). This is however far beyond the scope of this question.

  • 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-11T05:40:45+00:00Added an answer on June 11, 2026 at 5:40 am

    Maybe to_proc from Method can help you:

    class A
      def test
        puts 'this is a test'
      end
    end
    
    m = A.new.method(:test)
    
    m.to_proc.call #=> this is a test
    

    UPDATE: Just an idea

    By using sourcify gem convert proc from first object to source, and then evaulate it in the context of second object

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

Sidebar

Related Questions

Is there a simple way in Ruby to get a true/false value from something
From the client, is there a way to get a true/false value from an
Is there way to get file from windows xp command prompt? I tried to
is there way how to get name ov event from Lambda expression like with
Is there a way to get HTML contents from TinyMCE editor using jQuery so
Is there any way to get direct URL to a JSF bean action method?
Is there a way in jQuery to get the true opacity of an element?
I can't quite believe this, but seems there's no way to get tweets from
Is there a simple and efficient way to get the true dimensions (in JavaScript)
Is there a way to get ruby to do a forced copy? FileUtils.cp_r seems

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.