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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:53:12+00:00 2026-05-13T15:53:12+00:00

In Ruby 1.8.7 I can do the following in order to get the subject

  • 0

In Ruby 1.8.7 I can do the following in order to get the subject of a binding object:

binding.eval("self")

However, in Ruby 1.8.6, the eval method is private, so I expose it like this:

class Binding
  public :eval
end

Which seems to work fine, however, binding.eval("self") returns the binding itself, not the subject of binding.

How can I get the subject of a binding in Ruby 1.8.6? The solution doesn’t need to pretty – it just needs to work until we can upgrade to 1.8.7.

  • 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-13T15:53:13+00:00Added an answer on May 13, 2026 at 3:53 pm

    I’ll bet at least a nickel eval('self', abinding) will work:

    #!/usr/bin/ruby1.8
    
    class Foo
    
      def foo
        binding
      end
    
    end
    
    p eval('self', Foo.new.foo)    # => #<Foo:0xb7bfe5ac>
    

    This works because if you pass a binding to eval, it evaluates the string in the context of that binding. self in the context of the binding is whatever self was when the binding was created.

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

Sidebar

Related Questions

In Ruby 1.9, I can use its class variable like the following: class Sample
In order to implement auto-vivification of Ruby hash, one can employ the following class
Essentially I'm wondering if the following can be done in Ruby. So for example:
Possible Duplicate: Hex to binary in ruby In Python, I can do the following:
I can't do anything with Ruby anymore do the following reason: % gem install
I tried following the README file in Ruby 1.9.1 but I can't compile it
I was wondering how can I generate the following array using ranges in ruby
Can any one tell me? what does following means in ruby program: obj =
In Ruby I can call methods with array elements used as positional parameters like
I have a model called note . I currently get notes like this: current_user.notes.order('date

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.