Right now I am at the stage of learning. While studying Ruby I am finding (still continuing) that language looks quite simple but has its own complex and hidden secrets.
So, I am writing my experience of unexpected or peculiar behavior (Quirks) I have observed or will be going in future in this post.
1) Why following statement results into ‘nil’ ?
Assume that expand encountered here for the first time.
2) In the following Ruby code, x gets the value nil and pqr remains an undefined local variable. Why?
3) What is happening in following code and why, how?
4) Why expression 1 == 1.0
evaluates to true ?
Check following irb session:
5) In case of multiple values at right hand side(RHS) of assignment, the rules of parallel assignment come into play.
First, all the RHS values evaluated, left to right, and collected into an array (unless they are already an array). This array will be the eventual value returned by the overall assignment. Next, the left hand side (LHS) is inspected. If it contains a single element, the array is assigned to that element otherwise values get corresponding assignment.