Hi,
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
---
Thanks,
Marek
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
On 10/3/06, Marek Kralewski <mck-HuhXT4aU5K6ELgA04lAiVw@public.gmane.org> wrote:> > 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 > ---This is a Ruby quirk. It ''sees'' the local variable even if it''s never assigned when the program executes. For example:>> aNameError: undefined local variable or method `a'' for #<Object:0x2aaaaab232e0> from (irb):1>> if false; a = 1 end=> nil>> a=> nil jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Marek Kralewski
2006-Oct-03 17:32 UTC
Re: [Fwd: [Rails-core] Strange behavior with session]
Hi Jeremy, thanks for your answer. Am Dienstag, den 03.10.2006, 10:14 -0700 schrieb Jeremy Kemper:> 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... Thanks, Marek --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/3/06, Marek Kralewski <mck-HuhXT4aU5K6ELgA04lAiVw@public.gmane.org> wrote:> > > Hi Jeremy, > > thanks for your answer. > > Am Dienstag, den 03.10.2006, 10:14 -0700 schrieb Jeremy Kemper: > > > > 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...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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---