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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:46:29+00:00 2026-05-28T06:46:29+00:00

OK, Ruby gurus, this is a hard one to describe in the title, so

  • 0

OK, Ruby gurus, this is a hard one to describe in the title, so bear with me for this explanation:

I’m looking to pass a string that represents a variable: not an instance, not the collection of properties that make up an object, but the actual variable: the handle to the object.

The reason for this is that I am dealing with resources that can be located on the filesystem, on the network, or in-memory. I want to create URI handler that can handle each of these in a consistent manner, so I can have schemes like eg.

  • file://
  • http://
  • ftp://
  • inmemory://

you get the idea. It’s the last one that I’m trying to figure out: is there some way to get a string representation of a reference to an object in Ruby, and then use that string to create a new reference? I’m truly interested in marshalling the reference, not the object. Ideally there would be something like taking Object#object_id, which is easy enough to get, and using it to create a new variable elsewhere that refers to the same object. I’m aware that this could be really fragile and so is an unusual use case: it only works within one Ruby process for as long as there is an existing variable to keep the object from being garbage collected, but those are both true for the inmemory scheme I’m developing.

The only alternatives I can think of are:

  • marshal the whole object and cram it into the URI, but that won’t work because the data in the object is an image buffer – very large
  • Create a global or singleton purgatory area to store a variable for retrieval later using e.g. a hash of object_id:variable pairs. This is a bit smelly, but would work.

Any other thoughts, StackOverflowers?

  • 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-28T06:46:30+00:00Added an answer on May 28, 2026 at 6:46 am

    There’s ObjectSpace._id2ref :

    f = Foo.new #=> #<Foo:0x10036c9b8> 
    f.object_id #=> 2149278940 
    ObjectSpace._id2ref(2149278940) #=> #<Foo:0x10036c9b8>
    

    In addition to the caveats about garbage collection ObjectSpace carries a large performance penalty in jruby (so much so that it’s disabled by default)

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

Sidebar

Related Questions

Ruby-doc has this description: The ObjectSpace module contains a number of routines that interact
Ruby setters—whether created by (c)attr_accessor or manually—seem to be the only methods that need
Ruby on Rails has magic timestamping fields that are automatically updated when a record
Ruby's Time.parse() works for dates from Dec 14 1901 up Jan 18 2038 (this
Ruby docs don't mention this. Does Dir.glob(*) guarantee the order of the files it
Ruby 1.8.7, Rails 2.3.11 I've been trying the answers that appear to be what
Ruby has this great abstraction layer on top of Selenium called Capybara, which you
Calling regex gurus. I'm having some trouble right now with escaping a string in
ruby-1.9.2-p0 > Subscription => Subscription(id: integer, email: string, tuan: boolean, send: boolean, created_at: datetime,
Ok I've tried searching this site for other similar questions, but those that come

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.