Since the anonymous block and the hash block look pretty much the same. I played with him. And I do, I came to some serious observations, as shown below:
{}.class
Nice cool. an empty block is considered Hash.
print{}.class
puts {}.class
Now, why does the above code show the same thing as NilClass, but the code below shows again Hash?
puts ({}.class)
print({}.class)
Can someone help me here to understand what is happening above?
I totally disagree with @Lindydancer's point
As you explain the lines below:
print {}.class
print [].class
print (1..2).class
Why not the same with below print [].classand print (1..2).class?
EDIT
When ambiguity occurs when local variableand is called method, Ruby displays the error message described below:
name
#NameError: undefined local variable or method `name' for main:Object
# from (irb):1
# from C:/Ruby193/bin/irb:12:in `<main>'
{} ( empty code block Hash). IRB , a empty block Hash. , IRB print {}.class {}.class?