jruby

Shutdown hook for Rails

柔情痞子 提交于 2019-11-30 23:16:12
问题 I'd like to have some cleanup code run when Rails is shutting down - is that possible? My situation is that I have a few threads in the background (I'm using jruby and calling into java) that live for the life of the process and I need to let them know to shut themselves down Thanks! 回答1: Probably should just use the Ruby exit handler, which is a Kernel method: $ irb >> at_exit do ?> puts 'bye...' >> end => #<Proc:0xb79a87e4@(irb):1> >> exit bye... $ 回答2: Within the context of a Rails

What practical effect will different Ruby threading models (Ruby vs JRuby) have on your code as a developer?

断了今生、忘了曾经 提交于 2019-11-30 20:10:45
I'm trying to understand the practical impact of different threading models between MRI Ruby 1.8 and JRuby. What does this difference mean to me as a developer? And also, are there any practical examples of code in MRI Ruby 1.8 that will have worse performance characteristics on JRuby due to different threading models? State ruby 1.8 has green threads, these are fast to create/delete (as objects) but do not truly execute in parallel and are not even scheduled by the operating system but by the virtual machine ruby 1.9 has real threads, these are slow to create/delete (as objects) because of OS

Conditional gem dependencies

不想你离开。 提交于 2019-11-30 19:19:28
Is it possible to conditionally set a dependency on a gem at install time? Here's my situation which will hopefully clarify the question. There is a gem I maintain that depends on the json gem. However, I frequently use jruby which has a port of the json gem that's called json-jruby. To work around this I have to build two separate gems for each dependency. I'd like to build one gem that either says it depends on json OR json-jruby, or it checks at install time and uses the right dependency. Anyone have a good solution to this? Hmm, I believe one can code multiple dependencies because I've

JRuby: import vs include vs java_import vs include_class

不问归期 提交于 2019-11-30 12:34:04
问题 why so many different ways to include Java classes into JRuby? What are the differences? Which one should I use? 回答1: You can find quite a few examples about working with Java classes at: https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby It states, that you should use java_import instead of import due to the JRUBY-3171 bug. Also include_class is or will be deprecated (JRUBY-3797) in favor of java_import . Currently java_import is the recommended way to import a Java class. 回答2: import

Ruby daemons and JRuby - alternative options

℡╲_俬逩灬. 提交于 2019-11-30 09:57:13
I have an app that I am migrating from Ruby to JRuby (due to need for better Web Service Security support via Java). One of the gems I use is daemons to create a background job. The issue is that it use fork+exec to create the background process, but thats a no-no with JRuby. So - is there an alternative gem/wrapper for creating background jobs? My current thoughts are to just call rake from a shell script and let the rake task run forever... Thanks in advance, Chris. UPDATE We are currently using a couple of Java threading related wrappers, namely https://github.com/jmettraux/rufus-scheduler

How to run Ruby 2.0 with JRuby 1.7?

喜夏-厌秋 提交于 2019-11-30 05:52:15
What is the best way to get JRuby to run in 2.0 mode? For a specific script, you can use the --2.0 option: jruby --2.0 -S rails s For setting 2.0 as the default value, set JRUBY_OPTS : export JRUBY_OPTS=--2.0 You can also set the value in ~/.jrubyrc : compat.version=2.0 来源: https://stackoverflow.com/questions/15281036/how-to-run-ruby-2-0-with-jruby-1-7

What practical effect will different Ruby threading models (Ruby vs JRuby) have on your code as a developer?

℡╲_俬逩灬. 提交于 2019-11-30 04:42:30
问题 I'm trying to understand the practical impact of different threading models between MRI Ruby 1.8 and JRuby. What does this difference mean to me as a developer? And also, are there any practical examples of code in MRI Ruby 1.8 that will have worse performance characteristics on JRuby due to different threading models? 回答1: State ruby 1.8 has green threads, these are fast to create/delete (as objects) but do not truly execute in parallel and are not even scheduled by the operating system but

How to install Nokogiri Gem for Windows

谁说我不能喝 提交于 2019-11-30 04:04:47
I'm having this problem with nokogiri's gem: Could not open library 'C:\Ruby187\lib\ruby\gems\1.8\gems\nokogiri-1.4.6-x86-mingw32\ext\nokogiri\libxml2.dll' : unknown I read that I had to try the 1.5.0.beta3 version. However, when I run C:\Users\t3en4>gem install nokogiri --pre Fetching: nokogiri-1.5.0.beta.4.gem (100%) ERROR: Error installing nokogiri: The 'nokogiri' native gem requires installed build tools. Please update your PATH to include build tools or download the DevKit from 'http://rubyinstaller.org/downloads' and follow the instructions at 'http://github.com/oneclick/rubyinstaller

Compile jruby “Hello world” problem

一曲冷凌霜 提交于 2019-11-30 04:04:08
I have been programming for a while with Ruby and I really enjoy it. Lately I started having the need of compiling some ruby code. For several reasons using Ruby2exe is not an option for me. So I decided to give Jruby a try (generating a jar would be good enough). I am using windows and I installed java JDK 6u17 (at C:\Program Files\Java\jdk1.6.0_17). I installed jruby 1.4 at C:\jruby I created a hello world in java, compile and executed it just fine (so java works fine). I created a file "script.rb" with: puts "Hello, world" I run this program with jruby: jruby script.rb And it works fine. I

Conditional gem dependencies

China☆狼群 提交于 2019-11-30 04:03:55
问题 Is it possible to conditionally set a dependency on a gem at install time? Here's my situation which will hopefully clarify the question. There is a gem I maintain that depends on the json gem. However, I frequently use jruby which has a port of the json gem that's called json-jruby. To work around this I have to build two separate gems for each dependency. I'd like to build one gem that either says it depends on json OR json-jruby, or it checks at install time and uses the right dependency.