ruby

Ruby Integer to Binary string

I need to encrypt a integer, but all the crypto libraries only support strings. What is the proper method to convert a integer to a binary string in Ruby? (not '10111', I think that it's ASCII values) EDIT: I wasn't thinking about Rijndael as stream encryption. ...

Ruby coding style guidelines

Is there a document for Ruby that describes some preferred conventions for whitespace, indentation and other style issues? I found Python's PEP 8 to be very helpful and am looking for something similar for Ruby. ...

How do I install a RubyGem from NetBeans that I created?

Is it possible to install a RubyGem that I created in NetBeans, through NetBeans without uploading it to RubyForge? ...

Why am I getting this Cache-money error?

I followed the instructions found on the github page exactly. I would post some of my configuration but it matches what's found here on http://github.com/nkallen/cache-money/tree/master The error reads as follows: /!\ FAILSAFE /!\ Thu Mar 05 16:45:09 -0500 2009 Status: 500 Internal Server Error undefined method `indices' for nil:...

Do threads work in Ruby Shoes yet?

Any work going on to get other ruby threads working with Shoes? ...

What's a better way to sort by day date?

I have an Array of Events and I want to divide them into a 2-dimensional Array based on event_date (which returns a Time object). But I want it to be by the day part of the date. Here's what I have so far: def divide_events_by_day(events) # Sort, so we can start with the first day. events = events.sort { |x,y| x.event_date <=> y.eve...

Where is Time.advance documented?

Looking around on the Web I found that the Ruby Time class has Time#advance. Where is this documented? I saw no mention of it in the Ruby API docs here. The search function for the API docs indicated that there is no method called "advance" anywhere. Nonetheless, in IRB... >> t = Time.now => Thu Mar 05 16:08:57 -0800 2009 >> t.advance...

Tests suddenly erroring out. Anyone seen this error?

Ruby 1.8.6, Rails 2.2.2, OS X Tiger My Test::Unit tests started returning the error below. The relevant line seems to be: `load_missing_constant': Expected /Users/ethan/project/mtc/webcalendars/app/models/calendar.rb to define Calendar (LoadError) The file mentioned, calendar.rb looks fine. I can't find any errors in it. I trie...

Installing PL/Ruby for PostgreSQL

This is to enable the development of postgres functions with embedded ruby code, but I have been unable to build it. As advised by http://www.robbyonrails.com/articles/2005/08/22/installing-untrusted-pl-ruby-for-postgresql I am trying to build the needed plruby.so from the latest version (plruby-0.5.3.tar.gz) provided at ftp://moulon...

Is there a helper method for pluralization in Rails?

def plural(value, string) "#{value} #{value.abs == 1 ? string.singularize : string.pluralize}" end If not, what would be a short, sweet name for this method? ...

The ordinal parsing problem

Rails has a nice function, ordinalize, which converts an integer to a friendly string representation. Namely 1 becomes 1st, 2 becomes 2nd, and so on. My question is how might one implement the inverse feature? To be more general I'd like to handle both of the following cases: >> s = "First" >> s.integerize => 1 >> s = 1st >> s.integeri...

What platform would you recommend to develop a SAAS application?

Should I use LAMP, .Net, or any other platform? I have access to resources with LAMP, .Net, ROR and Java experience. Thanks. Sorry for being vague. Could you give me a few pluses and minuses of each like Paul? Thanks for your time and effort. ...

Rails: I can't call a function in a module in /lib - what am I doing wrong?

I know I'm doing something stupid or failing to do something intelligent - I'm frequently guilty of both. Here's an example of what's causing me pain: I have a module saved in /lib as test_functions.rb that looks like this module TestFunctions def abc puts 123 end end Going into ruby script/runner, I can see that the module ...

Why does question mark get interpreted as "z" in Ruby

Why does this line output "z" instead of "?" $ ruby -e 'puts %x[ echo #{"?"} ]' Suppose the expression inside the #{...} is a variable that may have the value of "?". How should I modify this script so that the question mark is outputted instead of "z"? (Please forgive the title of this question -- I don't yet understand what is going...

How to order string columns differently.

I have a has_many association like this: has_many :respostas_matriz_alternativas, :class_name => 'RespostaMatrizAlternativa', :order => 'respostas_matriz.codigo asc', :include => :resposta_matriz Well the fragment that matters is the "order". Codigo is a varchar column wich will contain in most cases numeric value...

Redirecting to a 500 page when an AJAX call fails in Ruby on Rails

I'm working with an application built in Ruby on Rails with very poor error handling right now. If a controller method is executed via ajax, and that method results in a 500 (or 404 or any other response) the 500.html page is rendered and returned as the result to the AJAX request. Obviously the javascript doesn't know what to do with th...

Rails: filter defined in lib file required in environment.rb disappears from filter_chain in production environment. Why?

Hi, In my rails application, I have a file in lib that, among other things, sets up a filter that runs on all controllers. When running under development environment, everything runs fine. However, under production the filter goes missing. Funny thing is, by inspecting the filter_chain, I noticed other filters remain, eg. those define...

Ruby file force copy

Is there a way to get ruby to do a forced copy? FileUtils.cp_r seems not to have a :force => true option. ...

Rails: Image cropping with Paperclip, S3 and RMagick.

Hey all, I'm currently trying to code a custom image cropping system similar to other ones on the internet where a user can select a cropping area and then have their image cropped accordingly. The application is in Rails and we're using Paperclip with Amazon S3 to store the files. I'm having a lot of trouble though getting RMagick to ...

How do you test code that is not a model or controller

I have a class defined in a file my Rails project's lib dir that will implement a bunch of utility functions as class methods. I'd like to write tests against those methods using Test::Unit and have them run as part of the project's regular testing routine. I tried sticking a file at the top level of the test dir... require 'test_helpe...