forked from spatten/ruby_koans
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimenting with more java interop
- Loading branch information
Marc Peabody
committed
Sep 28, 2010
1 parent
45523c0
commit 9b97fea
Showing
7 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,7 @@ task :test do | |
ruby 'path_to_enlightenment.rb' | ||
end | ||
|
||
task :java do | ||
`javac **/*.java` | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.edgecase; | ||
|
||
import java.util.Random; | ||
|
||
class JavaStuff{ | ||
public static final Random GENERATOR = new Random(System.currentTimeMillis()); | ||
public static final int DEFAULT_MAX = 100; | ||
|
||
public JavaStuff(){} | ||
|
||
public int randomNumber(){ | ||
return randomNumber(DEFAULT_MAX); | ||
} | ||
|
||
public int randomNumber(int max){ | ||
return GENERATOR.nextInt(max) + 1; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.edgecase; | ||
|
||
import org.jruby.Ruby; | ||
import java.lang.reflect.Method; | ||
import java.util.Map; | ||
import javax.script.ScriptEngine; | ||
import javax.script.ScriptEngineManager; | ||
import javax.script.ScriptException; | ||
|
||
|
||
class JavaToRuby{ | ||
public static final Ruby RUBY_RUNTIME = Ruby.getDefaultInstance(); | ||
public static final int DEFAULT_MAX = 100; | ||
|
||
public JavaToRuby() {} | ||
|
||
public Object randomNumber() throws ScriptException{ | ||
return randomNumber(DEFAULT_MAX); | ||
} | ||
|
||
public Object randomNumber(int max) throws ScriptException{ | ||
ScriptEngine jruby = new ScriptEngineManager().getEngineByName("jruby"); | ||
/* jruby.put("message", "hello world"); */ | ||
return jruby.eval("puts 'craaaaaaaap!!!!'; rand "+max); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include Java | ||
|
||
number_generator = com.edgecase.JavaToRuby.new | ||
puts number_generator.random_number | ||
puts "*"*20 |