当前位置:网站首页>Ruby: how to copy variables without pointing to the same object- Ruby: how can I copy a variable without pointing to the same object?
Ruby: how to copy variables without pointing to the same object- Ruby: how can I copy a variable without pointing to the same object?
2022-07-02 13:03:00 【Bustling city 】
problem :
In Ruby, how can I copy a variable such that changes to the original don't affect the copy? stay Ruby in , How to copy variables so that the original changes do not affect the copy ?
For example: for example :
phrase1 = "Hello Jim"phrase2 = phrase1phrase1.gsub!("Hello","Hi")p phrase2 #outputs "Hi Jim" - I want it to remain "Hello Jim"In this example, the two variables point to the same object; In this case , Two variables point to the same object ;I want to create a new object for the second variable but have it contain the same information initially. I want to create a new object for the second variable , But initially it contained the same information .
Solution :
Reference resources : https://stackoom.com/en/question/69GD边栏推荐
- Mongodb redis differences
- Mobile layout (flow layout)
- Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
- Floyd AcWing 854. Floyd finds the shortest path
- JDBC 预防sql注入问题与解决方法[PreparedStatement]
- 腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
- Hundreds of web page special effects can be used. Don't you come and have a look?
- VLAN experiment
- 阿里发布的Redis开发文档,涵盖了所有的redis操作
- Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
猜你喜欢

Enhance network security of kubernetes with cilium

8 examples of using date commands

Counting class DP acwing 900 Integer partition

Rust search server, rust quick service finding tutorial

Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))

包管理工具

Hash table acwing 841 String hash

上手报告|今天聊聊腾讯目前在用的微服务架构

Linear DP acwing 902 Shortest editing distance

spfa AcWing 851. SPFA finding the shortest path
随机推荐
哈希表 AcWing 841. 字符串哈希
Dijkstra AcWing 850. Dijkstra求最短路 II
Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)
[200 opencv routines] 100 Adaptive local noise reduction filter
Floyd AcWing 854. Floyd求最短路
Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee
Async/await asynchronous function
Analog to digital converter (ADC) ade7913ariz is specially designed for three-phase energy metering applications
浏览器node事件循环
模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
C modifier
Enhance network security of kubernetes with cilium
Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
Js4day (DOM start: get DOM element content, modify element style, modify form element attributes, setinterval timer, carousel Map Case)
Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
async/await 异步函数
spfa AcWing 852. SPFA judgement negative ring