当前位置:网站首页>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边栏推荐
- Browser storage scheme
- Js1day (input / output syntax, data type, data type conversion, VaR and let differences)
- 阿里发布的Redis开发文档,涵盖了所有的redis操作
- JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
- [ybtoj advanced training guidance] cross the river [BFS]
- JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
- 接口测试面试题目,你都会了吗?
- 腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
- [opencv learning] [template matching]
- Js1day (syntaxe d'entrée / sortie, type de données, conversion de type de données, Var et let différenciés)
猜你喜欢
![[opencv] [image gradient]](/img/37/1f366501e2b4e70ecee6365088167c.jpg)
[opencv] [image gradient]

3 A VTT端接 稳压器 NCP51200MNTXG资料

js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)

How can attribute mapping of entity classes be without it?

Hash table acwing 840 Simulated hash table

Apply lnk306gn-tl converter, non isolated power supply

JSON serialization and parsing

Linear DP acwing 897 Longest common subsequence

阿里发布的Redis开发文档,涵盖了所有的redis操作

spfa AcWing 851. spfa求最短路
随机推荐
基于STM32的OLED 屏幕驱动
Ntmfs4c05nt1g N-ch 30V 11.9a MOS tube, pdf
Linear DP acwing 902 Shortest editing distance
moon
Do you know all the interface test interview questions?
Redis avalanche, penetration, breakdown
[opencv learning] [image pyramid]
Dijkstra AcWing 850. Dijkstra求最短路 II
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
Structured data, semi-structured data and unstructured data
Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee
Redis introduction, scenario and data type
Floyd AcWing 854. Floyd求最短路
线性DP AcWing 896. 最长上升子序列 II
C modifier
8 examples of using date commands
bellman-ford AcWing 853. Shortest path with side limit
Linear DP acwing 898 Number triangle
2.7 binary tree, post order traversal - [FBI tree]
Heap acwing 838 Heap sort