新手问题 Ruby 的 String 有什么方法能够把字符串的值重写吗?

ibachue · May 21, 2013 · Last by iBachue replied at May 21, 2013 · 2307 hits

Hi all,

Ruby 的 String 有没有提供什么方法能够把一个字符串完全重写的?

比如

a = 'hello world'
b = a
a.Xxxx 'ruby china'
b.should == 'ruby china'

的办法?

我现在只能想到的最简单的办法是用

a[0..-1] = 'ruby china'

但是看上去不美观 Ruby 有啥原生方法实现不? 谢谢

String#replace ?

#1 楼 @doitian 不错 谢谢!

You need to Sign in before reply, if you don't have an account, please Sign up first.