ruby

What is ruby's StringIO class really?

I think I understand StringIO somewhat as being similar to java's StringBuffer class, but I don't really understand it fully. How would you define it and it's purpose/possible uses in ruby? Just hoping to clear up my confusion. Thanks ...

How can I turn my Rails app into a plugin?

I am currently developing a cms and want to reuse the functionality in other projects. ...

Very strange behaviour when launching Ruby daemons from bash script upon boot

I am using Rightscale to launch an instance on Amazon EC2. All my boot scripts work great and do things like getting the below file names in the folders. The last boot script is the following: #!/bin/bash MAINDIR="/root/username/" ruby ${MAINDIR}insertfd_control.rb stop ruby ${MAINDIR}insertfd_control.rb start ruby ${MAINDIR}inser...

rails i18n date problem

hey! we are currently working on a rails project that uses i18n and we have small problem with the dates: # on my mac "10.06.2008".to_date # produces => Tue, 10 Jun 2008 # on a friends mac and on the production server "10.06.2008".to_date # produces => ..., 06 Oct 2008 As you can see the dates aren't right. We checked everything. T...

regexp to match string1 unless preceded by string2

Using Ruby, how can I use a single regex to match all occurrences of 'y' in "xy y ay xy +y" that are NOT preceded by x (y, ay, +y)? /[^x]y/ matches the preceding character too, so I need an alternative... ...

Running ActiveRecord validations without saving

I have a collection of ActiveRecord objects. I want to be able to run all the validations for each of these objects without actually saving them to the database. I just want to know if they would be valid were I to save them to the database. In other words, I essentially want to populate the errors data structure for each of my objects...

Make text transparent in Shoes.app

Is there a way in Shoes to have text show up transparent? I have: Shoes.app{ para "Text", :stroke => rgb(1.0,0.0,0.0,0.5), :size => 100 } But it's just showing up 100% red. I know opacity works for fill, does it also work for stroke? (I am developing with Shoes Raisins Revision 1134 on Mac OS X 10.4.11) Thanks in advance ...

Calculate the derivative ([i] - [i - 1]) in Ruby.

Trivial using a for loop or each_with_index, just wondering if there was a better way of doing it using Ruby syntax. I need to create a new array that is the derivative of the source array, eg: for(int i = 1; i < oldArray.length; i++) { newArray[i] = oldArray[i] - oldArray[i-1] } ...

Ruby Email Client Recommendation

We are writing an email web client in Ruby to handle (potentially international) emails. I am looking for a high-level email library that supports retrieving emails, parsing email raw, decoding MIME, and converting input into UTF-8. Is there a library that you can recommend? ...

Ruby unit testing: how to fake Time.now?

What's the best way to set Time.now for the purpose of testing time-sensitive methods in a Unit test? Thanks! ...

Unable to run ruby on rails app?

I am unable to run ruby on rails application. I setup the database and loaded database schema. When I run: ruby script/server -e production It says: => Booting Mongrel => Rails 2.3.2 application starting on http://0.0.0.0:3000 => Call with -d to detach => Crtl-C to shutdown server and it just stays there. If I go to the directory w...

Using acts_as_state_machine transition methods without saving

I want to be able to utilize the acts_as_state_machine transition methods which are auto-generated (e.g. event!).. but I don't want it to save right away. I'm updating the state as part of another set of operations, and so I don't want to be doing double saves. Is there any way to trigger these event methods without a save right afterwa...

Dynamic Regex in Ruby

I am trying to find a way to let me dynamically create a regexp object from a string (taken from the database) and then use that to filter another string. This example is to extract data from a git commit message, but in theory any valid regexp could be present in the database as a string. What happens >> string = "[ALERT] Project: Rev...

How to paginate blog posts in a Rails application

I tried the following code but it doesn't work class BlogsController < ApplicationController def index #@entry_pages = Paginator.new(self, Entry.count, 10, params[:page]) @entries = Entry.find(:all, #:limit => @entry_pages.items_per_page, #:offset => @entry_pages.current.offset, :order => 'entries.created_at DESC',...

What does map(&:name) mean in Ruby?

...

Ruby on rails model with multiple parents

In my Rails application, I have two models, Articles and Projects, which are both associated with a user. I want to add comments to each of these models. What's the best way to structure this? Here's my current setup: class Comment < ActiveRecord::Base belongs_to :article belongs_to :project end class Article < ActiveRecord::Base ...

How to add GtkMozEmbed browser into a tab with Ruby/Glade/GtK?

Hey guys, I am trying to add a browser using GtkMozEmbed into a gui I am designing using Glade. I want the browser to take up a tab in a notebook widget, but I cannot figure out how to actually do this. I am wondering what container to use to put the browser in, and the associated ruby code to actually embed the browser in this contain...

IO.popen - how to wait for process to finish?

I'm using IO.popen in Ruby to run a series of command line commands in a loop. I then need to run another command outside of the loop. The command outside of the loop cannot run until all of the commands in the loop have terminated. How do I make the program wait for this to happen, because at the moment the final command is running too ...

Python string templater

I'm using this REST web service, which returns various templated strings as urls, for example: "http://api.app.com/{foo}" In Ruby, I can then use url = Addressable::Template.new("http://api.app.com/{foo}").expand('foo' => 'bar') to get "http://api.app.com/bar" Is there any way to do this in Python? I know about %() templates, b...

Auto-comment model on migration in Rails?

I seem to recall that there was a plugin or Rake snippet that would put comments in various Model classes after running a migration? It's a chore to have to look at db/migrate/X when I want to see which fields a given model has. If not, I'll write one, of course. :) ...