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

  • Home
  • SEARCH
  • 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 924311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:19:56+00:00 2026-05-15T19:19:56+00:00

I would like to achieve the following by introducing a new operator (e.g. :=

  • 0

I would like to achieve the following by introducing a new operator (e.g. :=)

a := b = {}
b[1] = 2
p a # => {}
p b # => {1=>2}

As far as I understand, I need to modify the Object class, but I don’t know what to do in order to get what I want.

require 'superators'
class Object
  superator ":=" operand # update, must be: superator ":=" do |operand|
    # self = Marshal.load(Marshal.dump(operand)) # ???
  end
end

Could you help me with this?


Update

Ok, superators will probably not help me here, but I still want such operator. How can I (or you) create an extension for Ruby, which I could load as a module?

require 'deep_copy_operator'
a !?= b = {} # I would prefer ":=" but don't really care how it is spelled
b[1] = 2
p a # => {}
p b # => {1=>2}
  • 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-15T19:19:57+00:00Added an answer on May 15, 2026 at 7:19 pm

    First of all, the syntax for superators is

    superator ":=" do |operand|
      #code
    end
    

    It’s a block, because superator is a metaprogramming macro.

    Secondly, you have something going their with Marshal…but it’s a bit of magic-ish. Feel free to use it as long as you understand exactly what it is you’re doing.

    Thirdly, what you are doing isn’t quite doable with a superator (I believe), because self cannot be modified during a function. (if someone knows otherwise, please let me know)

    Also, in your example, a must first exist and be defined before being able to call the method := in it.

    Your best bet is probably:

    class Object
      def deep_clone
        Marshal::load(Marshal.dump(self))
      end
    end
    

    to generate a deep clone of an object.

    a = (b = {}).deep_clone
    b[1] = 2
    p a # => {}
    p b # => {1=>2}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to be able to achieve something like this: class Zot {
I would like to achieve the following: I want a free Application Lifecycle Management
I would like to achieve the following: On homepage load, display modal box Within
I would like to achieve the following structure: [gfhtfg..., kgjrfg..., asd, mrhgf, ] ^-------^
I would like to achieve the following: all the workflows created should have the
Thanks for a solution in C , now I would like to achieve this
So here's what I'm looking to achieve. I would like to give my users
I'd like to achieve the following schema: Table A: a_id (other columns) Table B:
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to create a strong password in C++. Any suggestions? I assume it

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.