Question: In CoffeeScript:

```
f = ->
  v = 5
  g = ->
    v
  g()

f() # returns 5 as expected

```

In Ruby:

```
def f
  v = 5
  def g
    v # undefined local variable or method `v' for main:Object (NameError)
  end
  g
end
f

```

Okay, so apparently JavaScript functions are set up to capture variables in the scope they are created in, but Ruby's methods are not. Is there a way to make Ruby methods behave like JavaScript functions in this regard?

Answer: 
You don't really define methods inside of methods in Ruby, but you can use `lambda`:

```
def f
  v = 5

  g = lambda do
    v
  end

  g.call
end

```
To add to the other answers, for most consistency with your CoffeeScript code, you would probably write:

```
f = lambda do
  v = 5

  g = lambda do
    v
  end

  g[]
end
f[]

```