Project

java

0.01
No commit activity in last 3 years
No release in over 3 years
The caffeine boost you need for your late-night coding sprints.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

Java™

The caffeine boost you need for your late-night coding sprints.

Why

Because Enterprise™

Install

gem install java or add gem 'java' to your Gemfile.

This gem requires Ruby 2.1.0+.

Usage

Currently, the following keywords are supported: new, void, byte, short, int, long, float, double, bool, char.

require 'java'

class MyClass
  public def initialize(name)
    @name = name
  end

  public void def main()
    puts "This is the main method from #{@name}"
    return nil
  end

  public int def returns_int()
    1
  end

  public int def not_int()
    'not int'
  end

  public byte def returns_byte()
    1
  end

  public byte def not_byte()
    128
  end
end
>> obj = new MyClass("my class")
=> #<MyClass:0x000001018333d8 @name="my class">
>> obj.main()
This is the main method from my class
=> nil
>> obj.returns_int()
=> 1
>> obj.not_int()
TypeError: Expected not_int to return int but got "not int" instead
>> obj.returns_byte()
=> 1
>> obj.not_byte()
TypeError: Expected not_byte to return byte but got 128 instead

Production Ready?

It has tests, if that's what you are asking.

Future Work

  • Bug: typed private and protected methods doesn't work
  • Bug: Kernel defines Array, Complex, Float, Hash, Integer, Rational and String which breaks new String() etc
  • Support more keywords: static, final, etc
  • Support int i = 1 and String str = "abc"
  • Support public String def returns_str; ...; end

Credits

Java™ is a registered trademark of Oracle and/or its affiliates.

@tenderlove and @jeremy first brought this to my attention. @amatsuda also has a similar gist.