The goal is to add a sub-module to a higher level module. The higher level module is derived from its name in a string. This works in one case and gives an unexpected syntax error in another case.
failing_meta:4: syntax error, unexpected '\n', expecting &. or :: or '[' or '.'
failing_meta:8: syntax error, unexpected keyword_end, expecting end-of-input
Well const_get('Foo') is syntactically a non-constant while const_get('Foo')::Bar is. This is the ultimate reason why working_meta works but failing_meta fails. If you want to meta-program you have to be explicit like const_get('Foo').module_eval { ... }.
So you are saying this is how it should work and not a bug? If that is true, I should close this. What do you mean when you say that Object::const_get('Foo')::Bar is syntactically a constant. Its contains characters that are not appropriate in constant names, like brackets and single quotes, and a method is called, const_get, to evaluate it. To me it is an expression a::b::c with two scope operators, two constants (Object and Bar) and one method call that returns a constant const_get('Foo') => Foo.
Ok, you make it very clear. Indeed, in working_meta 'Bar' is not a constant but a name when statement 'module' is evaluated. Statement 'module' syntactically requires a name that does not exist in the scope yet. That name can be preceded by an expression that results in a scope. Default is the current scope. Name and scope expression are separated by double colon.