当前位置:网站首页>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边栏推荐
- 正确遍历EntryList方法
- ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
- Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
- Interesting interview questions
- js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
- Some sudden program ideas (modular processing)
- async/await 异步函数
- Explain in detail the process of realizing Chinese text classification by CNN
- Browser storage scheme
- Typora+docsify quick start
猜你喜欢
JSON序列化 与 解析
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
C#修饰符
js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)
哈希表 AcWing 840. 模拟散列表
计数类DP AcWing 900. 整数划分
Mobile layout (flow layout)
阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
[ybtoj advanced training guidance] cross the river [BFS]
Execute any method of any class through reflection
随机推荐
面渣逆袭:MySQL六十六问,两万字+五十图详解!有点六
js1day(输入输出语法,数据类型,数据类型转换,var和let区别)
Rust语言文档精简版(上)——cargo、输出、基础语法、数据类型、所有权、结构体、枚举和模式匹配
上手报告|今天聊聊腾讯目前在用的微服务架构
[opencv learning] [contour detection]
Rust language document Lite (Part 1) - cargo, output, basic syntax, data type, ownership, structure, enumeration and pattern matching
三面阿里,有惊无险成功拿到offer定级P7,只能说是真的难
基于STM32的OLED 屏幕驱动
Visual studio efficient and practical extension tools and plug-ins
区间DP AcWing 282. 石子合并
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
一些突然迸发出的程序思想(模块化处理)
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
Redis sentinel mechanism and configuration
Execute any method of any class through reflection
[ybtoj advanced training guidance] judgment overflow [error]
Explain in detail the process of realizing Chinese text classification by CNN
std::vector批量导入快速去重方法
8 examples of using date commands