Can I create Ruby classes within functions bodies ?
I seem to be getting error which tells me its not allowed but I think it should be as classes are too objects here.
class A
def method
class B
end
end
end
This fails with error ‘class definition inside method body.
If we cant, why cant we create classes inside methods ?
However, why do you want to assign a constant inside a method? That doesn’t make sense: constants are constant, you can only assign to them once which means you can only run your method once. Then, why do you write a method at all, if it is only ever going to be run once, anyway?