ruby

What exactly is the singleton class in ruby?

It seems as if I'm missing the point or misunderstanding the significance of the singleton class in Ruby. I've heard and read it in many ways—some more complicated than others—and left more confused as to what it is. Is it a class in and of itself? Is it the reason why all objects belong to "class?" The concept in play here is fuzzy. I'm...

Creating routes with an optional path prefix

How can I go about making my routes recognise an optional prefix parameter as follows: /*lang/controller/id In that the lang part is optional, and has a default value if it's not specified in the URL: /en/posts/1 => lang = en /fr/posts/1 => lang = fr /posts/1 => lang = en EDIT Ideally, I'm looking to do this across many c...

Can Ruby really be used as a functional language?

Can Ruby really be used as a functional language? What are some good tutorials to teach this facet of the language? Note: I really want to use and stick with Ruby as my primary language so I am not interested at this point in being converted to YAFL (yet another functional language). I am really interested in how well Ruby's functio...

How can I reliably discover the full path of the Ruby executable?

I want to write a script, to be packaged into a gem, which will modify its parameters and then exec a new ruby process with the modified params. In other words, something similar to a shell script which modifies its params and then does an exec $SHELL $*. In order to do this, I need a robust way of discovering the path of the ruby exec...

Selenium RC: Run tests in multiple browsers automatically

So, I've started to create some Ruby unit tests that use Selenium RC to test my web app directly in the browser. I'm using the Selenum-Client for ruby. I've created a base class for all my other selenium tests to inherit from. This creates numerous SeleniumDriver instances and all the methods that are missing are called on each instan...

Buffered Multipart Form Posts in Ruby

I am currently using Net::HTTP in a Ruby script to post files to a website via a multipart form post. It works great for small files, but I frequently have to send very large files using this script, and HTTP#post only seems to accept post data as a String object, which means that the file I'm sending has to be read into memory before a...

How "self-documenting" can code be without being annoying?

I am not sure what the best practices are here, but I often see abbreviated variable names especially when the scope is small. So (to use simple Ruby examples) instead of def add_location(name, coordinates), I see things like def add_loc(name, coord)—and I might even see something like def add_loc(n, x, y). I imagine that longer names mi...

Ruby %x forks on 64-bit Linux, but not on 32, and only with specific syntax

Here's some Ruby code: puts %x{ pstree #{$$} } # never forks puts %x{ pstree '#{$$}' } # forks on amd64 only On 32-bit Ubuntu Dapper, I get this output: t.rb---pstree t.rb---pstree Which makes sense to me. But on 64-bit Ubuntu Hardy, I get this: t.rb---sh---pstree t.rb---pstree What's being shown here is that Ruby forks befor...

Parsing Atom & RSS in Ruby/Rails?

I'm looking for something that will let me parse Atom and RSS in Ruby and Rails. I've looked at the standard RSS library, but is there one library that will auto-detect whatever type of feed it is and parse it for me? ...

RAII in Ruby (Or, How to Manage Resources in Ruby)

I know it's by design that you can't control what happens when an object is destroyed. I am also aware of defining some class method as a finalizer. However is the ruby idiom for C++'s RAII (Resources are initialized in constructor, closed in destructor)? How do people manage resources used inside objects even when errors or exception...

Ruby gem testing before deployment

I'm creating a gem which has several scripts in the bin directory the utility classes in the lib directory and several tests in the test directory supertool bin toolA toolB lib supertool supertool.rb helper.rb test tc_main.rb tc_etc.rb Now, to run the tests before I even install the gem, I have the foll...

One Rails application, several domain names

I want to point several domain names to the same Rails application. The content is different for each domain, but the functionality and the structure of the application is the same. What is the best way to do this when it comes to server set up and routing? I will use nginx as a web server. ...

Rails: Sorting a query by params?

I am using running a simple find all and paginating with willpaginate, but I'd also like to have the query sorted by the user. The first solution that came to mind was just use a params[:sort] http://localhost:3000/posts/?sort=created_at+DESC @posts = Post.paginate :page => params[:page], :order => params[:sort] But the problem with ...

Create images of the page when url supplied programatically (Ruby, PHP)

I am wondering if there is any good way to create image of page when I have url. If people submit url's, I would like to be able to create an image of that page and store that somewhere. I am not sure if this can be done easily or not, I have no simple ideas how to do that. I was wondering before I do something really complicated, if yo...

How to install and run Ramazes Rapaste easiest?

I'm pretty familiar with Ruby and Ramaze, but I wanted to provide my Admins with an install howto, since they're more familiar with Tomcat and standard Apache installations. I tried it locally first and it got pretty long: sudo aptitude install ruby1.8 ruby1.8-dev rubygems1.8 sqlite3 wget http://www.geocities.jp/kosako3/oniguruma/arch...

Dictionary API or Library

Does anyone know of a good dictionary API or ruby library to lookup the definitions of words? I'm thinking it should work something like: I call get_definition(word) It returns the definition for that word (ideally in some way to easily format the definition for display. Thanks ...

Does Ruby support verbatim strings?

Is there support in Ruby for (for lack of a better word) non-escaped (verbatim) strings? Like in C#: @"c:\Program Files\" ...or in Tcl: {c:\Program Files\} ...

What "Pastie" alternatives are there? (installable)

I want to install a "pastie" in our local intranet. What are the alternatives to RaPaste and pastie.org? (the latter can't even be installed locally b/c it doesn't seem to be open source?) Edit: Doesn't have to be Ruby btw. Edit: What I mean with pastie is an app where you can share source code pastes instead of pasting it in an irc ch...

Managing database changes between a Rails and Java project

At a new job I started, we have both a Java application that handles most of the heavy lifting in the core business logic, and we also have a Rails application that of course handles the web interface to this server. Both of these access the same database. Up until now, most of the focus has been on the Java application, and as such, t...

Rake db:migration problem

Hi, i've got a unfinished project that a developer just didn't finish and didn't let any documentation about the installation process. I've downloaded the production directory to my windows machine (running InstantRails 2), i created the databases as required in the database.yml and i tried to run the rake:db:migrate --trace but i'm rece...