ruby

Is DRb.start_service thread-safe?

I have an issue attemping to do DRb.start_service from 3 separate forked processes, is DRb.start_service thread/process-safe? Out of the 3 processes, 2 start DRb servers fine, the 3rd hangs forever at the DRb.start_service line, I would like to know if this is a limitation of DRb, or a problem elsewhere in the code. ...

How to structure a large Ruby application?

I'm considering writing a (large) desktop application in Ruby (actually a game, think something like Angband or Nethack using Gtk+ for the GUI). I'm coming from a C#/.NET background, so I'm a little at a lost for how to structure things. In C#, I'd create many namespaces, like Application.Core, Application.Gui, etc). Parts of the applic...

Keeping a rake job running

Hi, I'm using delayed_job to run jobs, with new jobs being added every minute by a cronjob. Currently I have an issue where the rake jobs:work task, currently started with 'nohup rake jobs:work &' manually, is randomly exiting. While God seems to be a solution to some people, the extra memory overhead is rather annoying and I'd prefer...

Best way to install mulitple gems onto a computer?

Is there an easy way, when running a Ruby script, to get it to automatically install gems required for script? For example, consider these require statements at the top of a ruby script: require 'net/http' require 'fileutils' require 'archive/zip' Now, I know (as a human and programmer) that for this script to run on a given PC with ...

Non-trivial desktop apps that use Ruby?

I'm about to start a project developing a Ruby desktop application. I expect to to be fairly big and I want to learn techniques for dividing code among modules and other techniques for managing complexity. Most large apps I've looked at are Rails apps, but these aren't very helpful, because most of the work is done by Rails itself. What...

Execute code at end of Module/Class, like Ruby test/unit

Ruby's unit testing framework executes unit tests even though nobody creates unit test object. For example, in MyUnitTest.rb require 'test/unit' class MyUnitTest < Test::Unit::TestCase def test_true assert true end end and when i invoke that script as ruby MyUnitTest.rb test_true method gets executed automatically...

Rails Active Record: find in conjunction with :order and :group

I have a structure something like this: class User has_many :dongles has_many :licences, :through => :dongles end class Dongle has_many :licences belongs_to :user end class Licence belongs_to :dongle end However, time passes and the user eventually gets multiple licences for each dongle. Reasonably, the app wants to summa...

Selective Ruby array slicing

I've been slowly learning Ruby (at this point, maybe the first language I've invested any amount of time in actually learning) so this is probably going to be a very simple question for many of you. My toy project for my studies is, basically, a roguelike. Currently, I have a Map class that contains an array of Tile objects representing...

Ruby Code Translation Request

I have negligible Ruby syntax knowledge and was hoping someone would be kind enough to translate the function below into pseudo code and possibly provide an example of how it would be called? def in_list(num, list) list = [*list] list.each {|a,b| return (b)? num.sub(a,b) : a if num =~ a} nil end ...

Ruby, how should I design a parser?

Hello, I'm writing a small parser for Google and I'm not sure what's the best way to design it. The main problem is the way it will remember the position it stopped at. During parsing it's going to append new searches to the end of a file and go through the file startig with the first line. Now I want to do it so, that if for some reaso...

Jython or JRuby?

It's a high level conceptual question. I have two separate code bases that serve the same purpose, one built in Python and the other in Ruby. I need to develop something that will run on JVM. So I have two choices: convert the Python code to Jython or convert the Ruby to JRuby. Since I don't know any of them, I was wondering if anyone ca...

Best practice: How to split up associations-functions in controllers with equal-access models

Hello, I have 2 equal-access models: Users and Categories Each of these should have the standard-actions: index, new, create, edit, update and destroy But where do I integrate the associations, when I want to create an association between this two models? Do I have to write 2 times nearly the same code: class UsersController << Appl...

What kind of data type can be rounded off?

I am currently trying to round off a float number but i get an error message like: undefined method round_to for float 16.666667.. and my code for rounding off is option = [keys[count], (((o.poll_votes.count.to_f)/@general_poll.poll_votes.count.to_f)*100).round_to(1)] And what suprises me the most is that i have used this code a...

Running Sinatra app with Mongrel on Windows

I'd like to start a Sinatra app from Mongrel on Windows, rather than Sinatra starting Mongrel in the background. Is there a simple way to use Mongrel for Sinatra? It's looking for a rails app by default. Edit: Suggested solution is to simply run a VMWare or SunBox with real Linux and deal with the corporate issues that way. ...

Which is the most reliable web server to work with RoR in production or development?

Mongrel, Thin, Webrick, Passenger... Wich one is the most effective solution to put a RoR application in a production environment? Which one is the most flexible, and easier to install and setup under Windows for development environment? ...

solr sanitizing query

I am using solr with ruby on rails. It's all working well, I just need to know if there's any existing code to sanitize user input, like a query starting with ? or * ...

ImageMagick and RMagick Installation Problems

I've been trying to install ImageMagick using the Mac OS X installer from Ruby Forge and the RMagick code doesnt want to compile, it outputs: Can't install RMagick 2.10.0. Can't find the ImageMagick library or one of the dependent libraries. Check the mkmf.log file for more detailed information. and have_library: checking for Initial...

The Most Basic Nokogiri Program Fails -- Documentation Problem or Bug?

I decided to give Nokogiri a try, and copied the following program straight from http://nokogiri.rubyforge.org/nokogiri/Nokogiri.html (adding only the require 'rubygems' and the I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 constant): require 'rubygems' I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 = 1 require 'nokogiri'...

When is a Ruby class not that Ruby class?

I have this code in my controller for a Rails app: def delete object = model.datamapper_class.first(:sourced_id => params[:sourced_id]) if object.blank? render :xml => "No #{resource} with sourced_id #{params[:sourced_id]}", :status => :not_found and return end object.destroy render :xml => "", :status => :no...

ActiveResource timeout not functioning

I'm trying to contact a REST API using ActiveResource on Rails 2.3.2. I'm attempting to use the timeout functionality so that if the resource I'm contacting is down I can fail quickly - I'm doing this with the following: class WorkspaceResource < ActiveResource::Base self.timeout = 5 self.site = "http://mysite.com/restAPI" end Ho...