R
Robert Dober
Now I am a big user of 42 but you surely made a mistake here, freezeIt'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
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
=> #<Class:0xb7d5af90>
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 .