Class names in Ruby must begin with a capital litter, like constants:

class poke
end

==> ERROR: class/module name must be CONSTANT

On the other hand, dynamic assignment to constants is illegal:

def foo
	Joe = 5
	p Joe
end

==> ERROR: dynamic constant assignment

So suppose I have some method 'make_class' that returns a dynamically 
created class. I can do (outside a method):

def make_class
	Class.new
end

Bobik = make_class()

argh = Bobik.new
p argh.class

==> Bobik

Nice... But inside a method / class:

def make_class
	Class.new
end

def try_it
	Bobik = make_class()
end

==> ERROR: dynamic constant assignment

However, I can do:

def make_class
	Class.new
end

def try_it
	bobik = make_class()
	argh = bobik.new
	p argh.class
end

try_it

==> #<Class:0x2c17010>

This looks like a mismatch between two unrelated features (true, 
assigning to constants dynamically is fishy, but creating new classes 
isn't !), right ?

And why the class name 'Bobik' is printed, while #<Class:0x2c17010> is 
printed when the class name is in lowercase. Does the lowercase change 
anything semantically ?


-- 
Posted via http://www.ruby-forum.com/.