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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:39:34+00:00 2026-06-15T21:39:34+00:00

Just imagine a situation when the only information we know about Ruby’s object is

  • 0

Just imagine a situation when the only information we know about Ruby’s object is it’s human readable format:

#<User::Class::Element:0x2fef43 @field1 = 1, @field2 = two, @field3 = [1,2,3]>

The task is to write a method which could convert this representation to the object of the class pointed by this representation (of course with having an access to all appropriate namespaces, modules, classes and methods). For example:

obj = humanReadableFormat2Obj("#<User::Class::Element:0x2fef43 @field1 = 1, @field2 = \"two\", @field3 = [1,2,3]>") 
puts obj.field1      #=> "1"
puts obj.field2      #=> "two"
p obj.field3         #=> [1, 2, 3]
puts obj.class.to_s  #=> User::Class::Element

P.S. This task originates from the problem of synchronization of several large data bases. Instead of transfering objects from one data base to another in the binary format(hundreds of MB) you can transfer only a script (several KB) and execute it on another data base to create appropriate object.

  • 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-15T21:39:36+00:00Added an answer on June 15, 2026 at 9:39 pm

    The Ox and Oj gems (XML and JSON respectively) can serialize into relatively human readable Ruby objects. This would probably be a better solution, since the inspect method doesn’t always return all of the attributes of a Ruby object, as Sigurd mentioned in the comments.

    Example from the Ox docs:

    require 'ox'
    
    class Sample
      attr_accessor :a, :b, :c
    
      def initialize(a, b, c)
        @a = a
        @b = b
        @c = c
      end
    end
    
    # Create Object
    obj = Sample.new(1, "bee", ['x', :y, 7.0])
    # Now dump the Object to an XML String.
    xml = Ox.dump(obj)
    # Convert the object back into a Sample Object.
    obj2 = Ox.parse_obj(xml)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just imagine this simple situation: int temperature = 20; is there any possibility to
Situation: imagine one form for adding items to the database user correctly fill the
The Situation: Imagine two servers A and B. Server B just outputs a PDF
Is it possible ? Or I just imagine ?
Imagine a very big gwt project of application. This is just a some form
everyone. I'm just starting with django, so sorry for a possibly stupid question. Imagine,
just wanted to ask where I define initial class properties? From other languages I
Imagine situation: I have view directory with tons of different views. all views have
Lets imagine my situation (it's fake, of course)... I have web-site that have 1000
Let's imagine the situation: Two PC software , two development team, two different technology

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.