You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JRuby's include_package (mentioned in https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby) includes Java packages in JRuby on const_missing. However, it does not trickle down to subclasses/submodules nor nested-classes/nested-modules.
nested_inherited_jruby_include_package patches up JRuby to add that capability.
Example (nesting):
require'nested_inherited_jruby_include_package'classOuterClassinclude_packagejava.utilclassInnerClassdefinitializepArrays.asList(1,2,3)endendendOuterClass::InnerClass.new# prints #<Java::JavaUtil::Arrays::ArrayList:0x233fe9b6>
Example (inheritance):
require'nested_inherited_jruby_include_package'classSuperClassinclude_packagejava.utilendclassSubClass < SuperClassdefinitializepArrays.asList(1,2,3)endendSubClass.new# prints #<Java::JavaUtil::Arrays::ArrayList:0x7ce3cb8e>
Example (java inheritance):
moduleGUIinclude_package'javax.swing'include_package'java.awt.image'# BufferedImage# bellow won't work without accessing BufferedImage before :classShowImage < JFramepBufferedImage.new(10,20,BufferedImage::TYPE_BYTE_BINARY)endend# prints #<Java::JavaAwtImage::BufferedImage:0x2f112965>
This gem relies on Module#const_missing after it aliases it to Module#const_missing_without_nested_inherited_jruby_include_package
As such, it works optimally if your project and loaded gems do not override Module#const_missing
Implementation Note
To avoid method and constant pollution in Module, the implementation intentionally trades off code clarity for lack of pollution by not relying on methods, yet local lambdas, in modularizing logic.
Issue Reporting
This is an early alpha. It has only been used in a couple of projects. As such, there are no guarantees for its functionality. Please report any issues you might discover when using on your own projects.