N
Nick Brown
Consider the following Sinatra app:
require 'sinatra'
vara = "foo"
VARB = "bar"
helpers do
def geta
vara
end
def getb
VARB
end
end
get '/a' do geta end
get '/b' do getb end
When I run that and browse to /b, it displays "bar". When I browse to
/a, however, it produces the error: "undefined local variable or method
`vara'".
Why do these two variables differ in scope?
How can I declare a variable that has global scope but is not a
constant?
Thanks in advance...
require 'sinatra'
vara = "foo"
VARB = "bar"
helpers do
def geta
vara
end
def getb
VARB
end
end
get '/a' do geta end
get '/b' do getb end
When I run that and browse to /b, it displays "bar". When I browse to
/a, however, it produces the error: "undefined local variable or method
`vara'".
Why do these two variables differ in scope?
How can I declare a variable that has global scope but is not a
constant?
Thanks in advance...