mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-15 07:23:19 -04:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1dcd9babd4 |
@@ -10,7 +10,3 @@ task :test do
|
||||
ruby 'path_to_enlightenment.rb'
|
||||
end
|
||||
|
||||
task :java do
|
||||
`javac **/*.java`
|
||||
end
|
||||
|
||||
|
||||
@@ -75,7 +75,17 @@ class AboutJavaInterop < EdgeCase::Koan
|
||||
assert_equal __(true), java_string == ruby_string
|
||||
|
||||
# THINK ABOUT IT:
|
||||
#
|
||||
# Is there any possible way for this to be more wrong?
|
||||
#
|
||||
# SERIOUSLY, THINK ABOUT IT:
|
||||
#
|
||||
# Why do you suppose that Ruby and Java strings compare like that?
|
||||
#
|
||||
# ADVANCED THINK ABOUT IT:
|
||||
#
|
||||
# Is there a way to make Ruby/Java string comparisons commutative?
|
||||
# How would you do it?
|
||||
end
|
||||
|
||||
def test_however_most_methods_returning_strings_return_ruby_strings
|
||||
@@ -85,15 +95,4 @@ class AboutJavaInterop < EdgeCase::Koan
|
||||
assert_equal __(false), java_array.toString.is_a?(java.lang.String)
|
||||
end
|
||||
|
||||
def test_call_custom_class
|
||||
number_generator = com.edgecase.JavaStuff.new
|
||||
assert_equal __(true), number_generator.random_number > 0
|
||||
end
|
||||
|
||||
# FREAKS OUT
|
||||
# def test_call_ruby_to_java_to_ruby
|
||||
# number_generator = com.edgecase.JavaToRuby.new
|
||||
# puts number_generator.random_number
|
||||
# puts "*"*20
|
||||
# end
|
||||
end
|
||||
|
||||
Binary file not shown.
@@ -1,18 +0,0 @@
|
||||
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.
@@ -1,28 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
include Java
|
||||
|
||||
number_generator = com.edgecase.JavaToRuby.new
|
||||
puts number_generator.random_number
|
||||
puts "*"*20
|
||||
Reference in New Issue
Block a user