when I create the following method inside a controller which has
sessions enabled, the result I
get (“nil”) is not the one I am expecting (CGI::Session).
Has anybody an explanation for this strange behavior?
— code
def strange
if nil
raise “strange”
session = “whatever”
end
render :text => session.inspect
end
Am Dienstag, den 03.10.2006, 10:14 -0700 schrieb Jeremy K.:
This is a Ruby quirk. It ‘sees’ the local variable even if it’s never
assigned when the program executes. For example:
I understand. So a local variable is defined regardless of the program
flow. But why is a local variable assigned, when the method
self.session= exists? That made me some serious headache…
I understand. So a local variable is defined regardless of the program
flow. But why is a local variable assigned, when the method
self.session= exists? That made me some serious headache…
Because in this ambiguous situation you may be assigning a local
variable or
you may be calling a writer method. Ruby interprets it as assigning a
local
variable.
jeremy
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.