Out of curiosity, why are we prevented from making non-constant class
names? We can make anonymous classes, we can assign them to
variables, so why not this?
class foo
end
Any good reason?
Chris
Out of curiosity, why are we prevented from making non-constant class
names? We can make anonymous classes, we can assign them to
variables, so why not this?
class foo
end
Any good reason?
Chris
Chris Pine wrote:
Out of curiosity, why are we prevented from making non-constant class
names? We can make anonymous classes, we can assign them to
variables, so why not this?class foo
endAny good reason?
I think it's a design issue - Ruby (well Matz is trying to make you
program coherently.
Yes, you can do:
foo = Class.new do ... end
But you should think about what you're trying to achieve. Seeing
something like this in the code should alert you that there is some
clever, subtle trick going on.
When you look at the Code you should be able to understand it easily by
reading it. Keeping is simple - some_text is a method, ALL_COLORS is a
constant and SomeThing is a class - makes it easier. In your example is
'foo' a variable in some scope? a method from some parent class /
included module?
BTW, there are classes with small letters only:
irb(main):001:0> ObjectSpace.each_object(Class) { |k| p k if k.name =~
/^[a-z]/ }
#=> fatal
But that is obviously a very special case.
Cheers,
Assaph
Out of curiosity, why are we prevented from making non-constant class
names? We can make anonymous classes, we can assign them to
variables, so why not this?class foo
end
class Foo
def foo; puts 'foo'; end;
end
foo = Foo
foo.new.foo
Any good reason?
Some conceptual reason, I am sure
Chris
E
Le 19/4/2005, "Chris Pine" <glyconis@gmail.com> a écrit:
--
template<typename duck>
void quack(duck& d) { d.quack(); }