Category Ruby quiz (advanced)

Ruby Quiz (Advanced) #2

Question What would be the output of this code snippet? Solution The output is: derived base derived base That might appear as a surprising behavior for a class variable, which is in general shared between all derived classes. But the trick here is that the class variable var has been set in the child first (and […]

Ruby Quiz (Advanced) #1

Question What will be the output of the following code snippet? [gist]   Solution The output is 3, and not 300 as one might expect. The reason for this is in the nature of the Proc object, and thus how it deals with the return keyword. Contrast it with using a lambda instead of a […]