Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Outer
- class Inner; end
- class AnotherInner; end
- end
- class C
- import Outer: [:Inner, :AnotherInner]
- def f
- Inner
- end
- end
- class Class
- def import(constants)
- @imported_constants =
- (@imported_constants || {}).merge Hash[
- constants.flat_map { |namespace, names|
- [*names].map { |name| [name.to_sym, "#{namespace}::#{name}"] }
- }]
- end
- def const_missing(name)
- const_set name, eval(@imported_constants[name] || raise)
- end
- end
- module Outer
- class Inner; end
- class AnotherInner; end
- end
- class C
- include Outer
- def f
- Inner
- end
- end
- C.new.f # => Outer::Inner
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement