ruby

Ruby: How to break a potentially unicode string into bytes

I'm writing a game which is taking user input and rendering it on-screen. The engine I'm using for this is entirely unicode-friendly, so I'd like to keep that if at all possible. The problem is that the rendering loop looks like this: "string".each_byte do |c| render_this_letter(c) end I don't know a whole lot about i18n, but I ...

What are your strategies to keep the memory usage low?

Ruby is truly memory-hungry - but also worth every single bit. What do you do to keep the memory usage low? Do you avoid big strings and use smaller arrays/hashes instead or is it no problem to concern about for you and let the garbage collector do the job? Edit: I found a nice article about this topic here and another one here - old ...

Python Vs. Ruby for Metaprogramming

I'm currently primarily a D programmer and am looking to add another language to my toolbox, preferably one that supports the metaprogramming hacks that just can't be done in a statically compiled language like D. I've read up on Lisp a little and I would love to find a language that allows some of the cool stuff that Lisp does, but wit...

Ruby. How can I copy and paste in irb on Windows?

How can I copy and paste in irb (Interactive Ruby Shell) on Windows? ...

Inadvertent Session Hijacking Issue With Restful Authentication

I'm using the current version of restful_authentication that is found on github and I'm having a bunch of strange session issues. The server seems to be somehow assigning sessions to users it shouldn't be. This only happens when crossing the logged out/logged in barrier. Here's an example. With no sessions active on the server, I log in...

What is the fastest way to get to documentation for Ruby?

Say I'm writing some ruby code and I want to use the standard Date type to get the current date. Instead of using a search engine, is there a faster way to find the documentation for this class? I know I can get the methods for Date by typing Date.methods, but as far as I know this doesn't provide details about argument types or return ...

How do I parse a number from a String that may have a leading zero?

In ruby I am parsing a date in the following format: 24092008. I want to convert each section (year, month, date) into a number. I have split them up using a regex which produces three Strings which I am passing into the Integer constructor. date =~ /^([\d]{2})([\d]{2})([\d]{4})/ year = Integer($3) month = Integer($2) day = Int...

Ruby isPrime Method

('1' * N) !~ /^1?$|^(11+?)\1+$/ On the net, I found this piece of Ruby code that works for N >= 0 that determines whether or not N is a prime. From what I can tell, it looks like play with regex but I have no idea how it works. Could someone tell me how it works? ...

What's the best way to deploy a JRuby on Rails application to Tomcat?

I'm looking at ways to deploy a Ruby on Rails app (running on JRuby) to a Tomcat instance for testing. The tomcat instance is running on a Solaris server that I can SSH to. I've looked at using Capistrano, but there doesn't seem to be a lot out there about using it to deploy to Tomcat, or even about running it under JRuby, and I keep hi...

Calculating the size of Array::pack format string

How do you calculate the length of the string that would be returned by Array::pack? Is there something like Python's calcsize? ...

Is it idiomatic Ruby to add an assert( ) method to Ruby's Kernel class?

I'm expanding my Ruby understanding by coding an equivalent of Kent Beck's xUnit in Ruby. Python (which Kent writes in) has an assert() method in the language which is used extensively. Ruby does not. I think it should be easy to add this but is Kernel the right place to put it? BTW, I know of the existence of the various Unit framew...

How do I configure Apache 2.2 for Ruby on Rails in Windows?

I'm trying to get started writing some Ruby on Rails apps and have been successful with Mongrel but, I'd like to deploy my apps to my Apache 2.2 instance on Windows? All the tutorials I've found seem out of date and are for older versions of Apache/Rails. Does anyone know of a good, current tutorial for configuring Apache 2.2 for Ruby ...

What are your favorite Ruby on Rails books and why?

I'm looking to pick up a few books on RoR to help teach myself how to build a scalable RoR app. I have read the RailsSpace book, and am starting the Rails Way book tonight. Some topics of interest are: REST - considering using Amazon's SimpleDB Using RSpec effectively memcached - server architecture and code implementation mongrel -...

Continuations in Ruby

Has anyone ever done work to get Ruby to do continuations (like Seaside on Smalltalk)? ...

Using respond_to for graceful degradation with ajax in RoR 2.x

I was going through the AWDR book on web development with ruby on rails and one of the issues with the old code was it didn't use respond_to to make sure the view used would be the javascript view. Now in some updated examples I've seen people mention they later, when implementing graceful degradation, use request.xhr? to tell if the use...

How Do I Authenticate to ActiveResource to Avoid the InvalidAuthenticityToken Response?

I created a Rails application normally. Then created the scaffold for an event class. Then tried the following code. When run it complains about a InvalidAuthenticityToken when the destroy method is executed. How do I authenticate to avoid this response? require 'rubygems' require 'activeresource' class Event < ActiveResource::Base s...

Ruby - Regex String Insertion

I need to substitute the value of a string into my regular expression in Ruby. Is there an easy way to do this? For example: foo = "0.0.0.0" goo = "here is some other stuff 0.0.0.0" if goo =~ /foo's value goes here/ puts "success!" end ...

Ruby on Rails Content Management Systems?

Is there a viable open source Ruby on Rails content management system out there? I need a CMS with the ability to manage structured content, content relationships, classification (structured taxonomy and free tagging) and simple publishing workflow. I'd prefer the content ultimately be persisted as XML. Also content needs to be abst...

Custom method in model to return an object

In the database I have a field named 'body' that has an XML in it. The method I created in the model looks like this: def self.get_personal_data_module(person_id) person_module = find_by_person_id(person_id) item_module = Hpricot(person_module.body) personal_info = Array.new personal_info = {:studies => (item_module...

Ruby off the rails

Sometimes it feels that my company is the only company in the world using Ruby but not Ruby on Rails, to the point that Rails has almost become synonymous with Ruby. I'm sure this isn't really true, but it'd be fun to hear some stories about non-Rails Ruby usage out there. ...