This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.
| Converting Between Strings and Symbols | ||
|---|---|---|
| Code | Expected | Actual |
:a_symbol.to_s |
"a_symbol" | "a_symbol" |
:AnotherSymbol.id2name |
"AnotherSymbol" | "AnotherSymbol" |
:"Yet another symbol!".to_s |
"Yet another symbol!" | "Yet another symbol!" |
:dodecahedron.object_id |
4565262 | 4903182 |
symbol_name = "dodecahedron" symbol_name.intern |
:dodecahedron | :dodecahedron |
symbol_name.intern.object_id |
4565262 | 4903182 |
"string".object_id |
1503030 | -605976086 |
"string".object_id |
1500330 | -605979006 |
:symbol.object_id |
4569358 | 4907278 |
:symbol.object_id |
4569358 | 4907278 |
"string1" == "string2" |
false | false |
:symbol1 == :symbol2 |
false | false |