While trying to answer another member's question, I happened across this strange behaviour:
puts :some_object => 'another_object'
Surprisingly, the output is this:
{:some_object=>"another_object"}
What is this new devilry? It looks as though I've created a hash using #puts
, and without using the normal curly-bracket syntax.
I can't test this theory though, because this just generates an error:
puts (:some_object => 'another_object').class
# => syntax error, unexpected =>, expecting ')'
What's going on here?
Edit: Okay, thanks to bundacia's explanation, it's now easy for me to test and confirm that it's a hash (whereas I wasn't sure how to do that before):
def test(x)
puts x.class
end
test(:some_object => 'another_object')
# => Hash
Many thanks!