Coder Social home page Coder Social logo

nested_inherited_jruby_include_package

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'

class OuterClass
  include_package java.util
  class InnerClass
    def initialize
      p Arrays.asList(1, 2, 3)
    end
  end
end

OuterClass::InnerClass.new
# prints #<Java::JavaUtil::Arrays::ArrayList:0x233fe9b6>

Example (inheritance):

require 'nested_inherited_jruby_include_package'

class SuperClass
  include_package java.util
end

class SubClass < SuperClass
  def initialize
    p Arrays.asList(1, 2, 3)
  end
end

SubClass.new
# prints #<Java::JavaUtil::Arrays::ArrayList:0x7ce3cb8e>

Example (java inheritance):

module GUI
  include_package 'javax.swing'
  include_package 'java.awt.image' # BufferedImage
  # bellow won't work without accessing BufferedImage before :
  class ShowImage < JFrame
    p BufferedImage.new(10, 20, BufferedImage::TYPE_BYTE_BINARY)
  end
end
# prints #<Java::JavaAwtImage::BufferedImage:0x2f112965>

More examples can be found in:

spec/lib/core/src/main/ruby/jruby/java/core_ext/module_spec.rb

Setup

Add the following to Gemfile:

gem 'nested_inherited_jruby_include_package', '~> 0.3.0'

And, then run:

jruby -S bundle install

If you are not using Bundler, run:

jruby -S gem install nested_inherited_jruby_include_package -v 0.3.0

Then add this line to your code:

require 'nested_inherited_jruby_include_package'

Caveats

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.

Change Log

CHANGELOG.md

License

The MIT License

LICENSE.txt

Copyright

Copyright (c) 2020 Andy Maleh

Andy Maleh's Projects

abstract_feature_branch icon abstract_feature_branch

abstract_feature_branch is a Ruby gem that provides a variation on the Branch by Abstraction Pattern by Paul Hammant and the Feature Toggles Pattern by Martin Fowler (aka Feature Flags) to enable Continuous Integration and Trunk-Based Development.

are-we-there-yet icon are-we-there-yet

Are We There Yet? Small Project Tracking Desktop App for Windows and Mac. Built with Glimmer (Ruby Desktop Development GUI Library)

array_include_methods icon array_include_methods

Array#include_all?, Array#include_any?, Array#include_array?, Array#array_index, Array#array_diff_indices, Array#array_intersection_indices, Array#counts, and Array#duplicates operations missing from basic Ruby Array API

asker-gui icon asker-gui

GUI front end for Asker tool (under development)

awesome-ruby icon awesome-ruby

:gem: A collection of awesome Ruby libraries, tools, frameworks and software

awesome-ruby-1 icon awesome-ruby-1

A curated list of awesome Ruby frameworks, libraries and resources. Inspired by awesome-php & awesome-python.

awesome_print icon awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation

babel icon babel

🐠 Babel is a compiler for writing next generation JavaScript.

batman icon batman

Fighting Crime and Kicking Apps

befunge98 icon befunge98

GUI implementations by Glimmer DSL for SWT & Glimmer DSL for LibUI for the first Befunge-98 interpreter in Ruby

bundler-download icon bundler-download

Bundler plugin for auto-downloading specified extra files after gem install

carmen-rails icon carmen-rails

NOT ACTIVELY MAINTAINED Rails adapter for Carmen (provides country_select and subregion_select)

carrierwave icon carrierwave

Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks

catalog icon catalog

The Ruby Toolbox library catalog. If you'd like to contribute to the categorizations of Ruby open source projects on the Ruby Toolbox this is the place you can do so 📬🎉

ci_uy icon ci_uy

A gem to validate Uruguayan Identity Documents (Cedula de Identidad Uruguaya)

clibui icon clibui

Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.