From: Robert Dober Date: 2008-05-23T17:50:41+09:00 Subject: Re: Prevent ruby constant variables from changing? On Thu, May 22, 2008 at 11:12 PM, Sebastian Hungerecker wrote: > Jeremy Hinegardner wrote: >> I didn't know that what >> is returned from the end of a class ... end and module .. end block is >> NilClass. > > It's not. A class/module ... end block returns the value of the last > expression in it. So > module C > X = 42 > end.freeze > calls freeze on 42 Now I am a big user of 42 but you surely made a mistake here, freeze has to be called on 32, right? (Hint: here in Europe we rather call it on 0). Well this is offtopic, let us get ontopic again ;) I feel it is interesting how many different views we got here on the subject... look at these semantics 517/17 > irb irb(main):001:0> class A irb(main):002:1> end => nil irb(main):003:0> B = A => A irb(main):004:0> class B irb(main):005:1> def a; 42 end irb(main):006:1> end => nil irb(main):007:0> A.new.a => 42 irb(main):008:0> B.name => "A" I just feel to think more seriously now never to use "class X" again, I want to avoid the very subtle inconsistencies it implies but I really hate, that after C = Class::new C.name equals "C". This is the first time ever since I discovered that blocks cannot have block parameters that I feel that Ruby stands in my way, no it is worse, Ruby overrules me, decides for me, that is *soooo* untypical for Ruby. And furthermore the former went away in 1.9 while the later did not. I guess I will write an RCR right away. You cannot even trick the parser!!! irb(main):001:0> C = _ = Class::new => C irb(main):002:0> C.name => "C" but finally irb(main):006:0> _ = Class::new => # irb(main):007:0> _.name => "" irb(main):008:0> X = _ => "" irb(main):009:0> X.name NoMethodError: undefined method `name' for "":String from (irb):9 from :0 irb(main):010:0> I get where I wanted :). > > HTH, > Sebastian > -- > NP: Depeche Mode - Master And Servant > Jabber: sepp2k@jabber.org > ICQ: 205544826 > > -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein