Skip to content

Instantly share code, notes, and snippets.

@blinsay

blinsay/pry.rb Secret

Created October 21, 2014 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blinsay/52571ba3b726c8ac0260 to your computer and use it in GitHub Desktop.
Save blinsay/52571ba3b726c8ac0260 to your computer and use it in GitHub Desktop.
[1] pry(main)> java_import java.util.concurrent.Executors
=> [Java::JavaUtilConcurrent::Executors]
[2] pry(main)> e = Executors.new_fixed_thread_pool(2)
=> #<Java::JavaUtilConcurrent::ThreadPoolExecutor:0x13df2a8c>
[3] pry(main)>
[4] pry(main)>
[5] pry(main)>
[6] pry(main)>
[7] pry(main)> class Foo
[7] pry(main)* include java.lang.Runnable
[7] pry(main)*
[7] pry(main)* def run
[7] pry(main)* sleep 2
[7] pry(main)* puts "hi there"
[7] pry(main)* end
[7] pry(main)* end
=> nil
[8] pry(main)>
[9] pry(main)>
[10] pry(main)>
[11] pry(main)> e.submit(Foo.new)
(pry):12 warning: ambiguous Java methods found, using submit(java.lang.Runnable)
=> #<Java::JavaUtilConcurrent::FutureTask:0xb83a9be>
[12] pry(main)> hi there
[12] pry(main)>
[13] pry(main)>
[14] pry(main)>
[15] pry(main)>
[16] pry(main)> e.java_send(:submit, [java.lang.Runnable], Foo.new)
TypeError: cannot convert instance of class org.jruby.RubyModule to class java.lang.Class
from org/jruby/java/proxies/JavaProxy.java:344:in `java_send'
[17] pry(main)> e.java_send(:submit, [Java::JavaLang::Runnable], Foo.new)
TypeError: cannot convert instance of class org.jruby.RubyModule to class java.lang.Class
from org/jruby/java/proxies/JavaProxy.java:344:in `java_send'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment