From: Andrea Dallera Date: 2010-12-20T05:15:13+09:00 Subject: Re: Regexp, String, Symbol literals' object_ids Ruby has both mutable and immutable strings. A mutable string is declared as "string". An immutable string is declared as :string and in ruby is called a 'symbol'. So, no, there is no way for "string" to behave as :string, since that's by design. Well there is a way but I'd not go there :-) If you want two equivalent string literals to point at the same instance, use the symbol notation, as in: :test.object_id == :test.object_id #true -- Andrea Dallera http://github.com/bolthar/freightrain http://usingimho.wordpress.com Andrea Il 19/12/2010 21:07, Pavel R. ha scritto: > Regexp literals: > 5.times { p /abcdasdf/.object_id } -> same! > > String literals: > 5.times { 'asdasdf'.object_id } -> different > > Symbols: > 5.times { p :asdfsf.object_id } -> same! > > Symbols with to_s: > 5.times { p :asdsdfsdf.to_s.object_id } -> different > > Predefined string as a constant > CONS = 'asdfsdf' > 5.times { p CONS.object_id } -> same! (sure) > > Question: > Is there some special syntax for string literals ("asdfasdf") to behave > like /sadfsdf/ as in the examples above? Without predefining a string as > a constant's value. Or another elegant way to achieve the same goal? >