See the following code:
1 str1 = gets
2 str2 = "Hello"
3 puts str1
4 puts str1.to_sym().object_id()
5 puts str2.to_sym().object_id()
6 puts :"Hello".object_id()
In Line 1, I input "Hello" from stdin and save this string to var str1. In Line 2, I save a string "Hello" to var str2. Now str1 and str2 contains same string, although they are different string object, and their values are same. According to rule of symbol, I except I can get game symbol of "Hello" from str1 and str2. But output is:
Hello
213748
213548
213548
It looks that str1 has different symbol from str2. How can I get symbol of "Hello" from str1?
I ask this question because I'm facing a problem that, I need to input some words from stdin, then use these words as key to build a hash table. As hash table should use symbol as key to avoid memory waste, I need to get symbol of input words.