ruby

Self-extracting web environment

Hi, Basically I have two applications: a PHP web application that runs over Apache and Mysql a ruby application that has been built with gem dependencies What I would like to be able to create is a self extracting archive; once all the files have been extracted into any directory, my users can just click two bat files: the first o...

In-line visualization of content age

I have two tables, pages and revisions. Revisions has a foreign key to a page. The contents of a page is the latest entry in the revisions table for that page. The revisions are full copies of the contents, no deltas. As an experiment, I would like to visualize the revision state of the current revision. If text is new in the current re...

Ruby 1.9.1 with rspec "can't modify frozen object"

I just updated to Ruby 1.9.1 and nearly all my rspec are broken giving me a "can't modify frozen object". Even the Rspec sample code from a generate rspec_controller fails. RuntimeError in 'DownloadsController should use DownloadsController' can't modify frozen object ...

Can't convert nil to string -- edited to restate all the failing attempts

At a point in my code, I expect current_part to sometimes be nil, and I want to run some code (inside an if block) when that's not the case. Using script/server --debugger, I've established that current_part is in fact nil at that point when the following errors occur. All the following versions generate the can't convert nil into Stri...

Difficult to use ActiveMerchant in a project that does not use ActiveRecord as its ORM?

ActiveMerchant seems to be baked with AR in mind. I've come to this conclusion based on the fact that the purchase() method returns an ActiveRecord::Billing::Response object: Is this correct and, if so, does this mean it might be difficult to use ActiveMerchant in a project that uses a different Ruby ORM (Sequel/Datamapper)? ...

How can I use a variable to access the fieldname of a ruby object in erb? ex. Model.task_#{variable}

I have a to-do list with 5 tasks that are stored on the same record. Todo.task_one, Todo.task_two, etc. What I would like to do is be able to loop through the fields like this total_tasks = ["one", "two", "three", "four", "five"] for tasks in total_tasks Todo.task_#{tasks} = "text here" end However, this doesn't work unless I use e...

PHP array with default value for nonexisting indices

I love the Hash implementation of Ruby where you can initialize the Hash object with a default value. At the moment I'm struggling with implementing a similar object in PHP. This is my first (non-working) shot at this. class DefaultArray extends ArrayObject { protected $_defaultValue; public function setDefault($defaultValue) { ...

Advanced Java-like enums in Ruby

First of all, this is not a duplicate of Enums in Ruby :) The accepted answer of that question suggests this as a good way to represent enums in Ruby: class Foo BAR = 1 BAZ = 2 BIZ = 4 end In Java it is possible to attach multiple values and methods to an enum value. I want to achive the same or something similar in Ruby. What...

How to display error type in ruby?

Hello, in the following code begin raise StandardError, 'message' #some code that raises a lot of exception rescue StandardError #handle error rescue OtherError #handle error rescue YetAnotherError #handle error end I want to print a warning stating the type and the message of the error without adding print statement to each of t...

Parsing a complex string of characters with Ruby

I need to parse an extremely complex string of characters to extract a particular section of it, which contains a foreign key to a database (the snippet comes from a product called Interspire Email Marketer and contains some weird logic to filter a contact list). The string in question is as follows (yes, I realize it's extremely weird....

Ruby code on NFS mount, using another file on same mount causes problems.

I'm working on an embedded system whoose details are explained at the end of this post. Tools are ruby on linux. I put my ruby code on a remote NAS device on network and mount it to the embedded system I'm working on using NFS v3. My project scenario is like this: there is an all-in-one auto starter which 1.mounts the nfs share, 2. star...

Ruby approach to data access available in IronRuby

Coming from the Ruby community and approching IronRuby for desktop application development, I have little interest in using a .NET based ORM such as Linq. I want to use the ruby-way of data access that I've come to love from products such as ActiveRecord, DataMapper, and Sequel. After much searching I ran into a brick wall trying to ge...

ruby edge cases

ruby has some edge cases which is hard to explain because parsing brings some interesting issues. Here I am listing two of them. If you know of more then add to the list. def foo 5 end # this one works if (tmp = foo) puts tmp.to_s end # However if you attempt to squeeze the above # three lines into one line then code will fail # t...

Ruby: auto-quote string, not other data, when writing to a file?

i'm writing a small library that writes data out to a file. some of the data is strings, some of it is not - things like boolean (true/false) values... when I have a string for data, I want to write the string to the file with quotes around it. so a string like "this is a string of data" would be written to the file with the quotes arou...

match "[" with ruby regular expressions

I want to match a string that includes the characters 0-9.-,[], something like this: return true if str =~ /\A[0-9.-,\[\]]*\Z/ Which works except it doesn't seem to match the braces, how do I match those? ...

Is there a way to test Comet applications without a running browser?

I'm trying to connect to an application that uses Comet and is pretty heavy on Javascript and Comet. I've gone as far as I can go in Firebug, HTTP Header examination and am trying to see what's coming over the wire by writing something using Ruby Mechanize. However, since I have no client run-time, my approach is to mimic the HTTP re...

How to list valid Iconv encodings in Ruby?

Hello, how to get a list of valid Iconv encodings in Ruby 1.9.1 under windows 7? ...

Ruby: how can I copy a variable without pointing to the same object?

In Ruby, how can I copy a variable such that changes to the copy don't affect the original? For example: phrase1 = "Hello Jim" phrase2 = phrase1 phrase1.gsub!("Hello","Hi") p phrase2 #outputs "Hi Jim" - I want it to remain "Hello Jim" In this example, the two variables point to the same object; I want to create a new object for the s...

Ruby: how can I copy this array?

(Follow-up to my earlier question, Ruby: how can I copy a variable without pointing to the same object?) I'm writing a simple Ruby program to make some substitutions in an .svg file. The first step is to pull information from the file and put it in an array. In order to keep from reading the file from disk every time this function is ca...

Mechanize setting a field with a duplicate name...

I'm using mechanize and have a problem on one form... the form has two select boxes with the same name. How can I select the second one? ie. NumNights second occurrence. i found in the docs something like this: form.set_fields( :foo => ['bar', 1] ) but this didn't work: form.field_with(:name => [ 'NumNights', 2 ]).options[no_days...