Dear list
in a very recent discussion I have realized that to many the meaning
of Class#name does not make sense or is confusing.
Problem:
X = Class::new
and even
X =_ = Class::new
delivers "X" as result of X.name
of course after Y = X we have
Y.name = "X"
but we can perfectly reopen X with the following syntax
class Y
...
end
As I believe that the dynamic semantics of assigning classes to
constants and variables are far too important to be dropped the
concept of a name of a class does not really make sense any more. I am
aware that thinking consequently into this direction should allow us
to write code like the following too. I release these thoughts for
comments too :)
class x
end
x.class --> Class
I fail to see a reason that
x = Class::new is allowed while
class x is not
Motivation:
This would be one of the occasions to make Ruby simpler, not only
would we get rid of a magically created attribute acessible by the
method Class#name, but the parser would need less work to do.
Proposal:
The following behavior should be implemented
535/35 > cat classes.rb && ruby1.9 classes.rb
# vim: sw=2 ts=2 ft=ruby expandtab tw=0 nu syn=on:
# file: classes.rb
class K; end
p K.name
classes.rb:5:in `remove_method': method `name' not defined in Class (NameError)
from classes.rb:5:in `<class:Class>'
from classes.rb:4:in `<main>'
BTW I do not give this RCR any chance, but I believe it is a good
idea, please surprise me ;).
Cheers
Robert