Question: In Section 14.4.1 we claimed that nested blocks in Ruby were part of the named scope in which they appear. Verify this claim by running

In Section 14.4.1 we claimed that nested blocks in Ruby were part of the named scope in which they appear. Verify this claim by running the following Ruby script and explaining its output:

def foo(x) y = 2 bar = proc { print x,

Now comment out the second line (y = 2) and run the script again. Explain what happens. Restate our claim about scoping more carefully and precisely.

def foo(x) y = 2 bar = proc { print x, " " y = 3 } bar.call() print y, " " end foo (3)

Step by Step Solution

3.49 Rating (166 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Language Pragmatics Questions!