ruby

Returning inside for loop inside lambda crashes in Ruby 1.8

In Ruby 1.8 (my version is 1.8.7-72), this code: foo = lambda do for j in 1..2 return end end foo.call crashes with a LocalJumpError: test2.rb:3: unexpected return (LocalJumpError) from test2.rb:2:in `each' from test2.rb:2 from test2.rb:6:in `call' from test2.rb:6 Why does it do this? However, it seems to ru...

DataMapper has_one problem

Hello. I`m having trouble associating models in DataMapper. Its really simple, but i just can get the idea. So, i have 2 tables: 1. Books -> id -> title -> publisher_id 2. Publishers -> id -> title The classes: class Book property :id, Serial property :title, String property :publisher_id, Integer end class Publisher prope...

What next after Chris Pine's Learn to Program

A couple of years ago I bought my younger brother Chris Pine's "Learn to Program" (with Ruby), and he's finally gotten around to reading it. And appears to be enjoying it. This is something I'm keen to encourage, so would like to know what's next? I don't want to confuse him with another language, so something Ruby would be ideal. Chee...

Getting only new mail from an IMAP server

I am writing a client application that fetches emails from an IMAP server and then stores them in a database. The problem is that once I have checked the mail, the next time I only want to download the mail that has arrived since. So if I had checked the server for mail two hour ago, I only want to get the mail that has arrived in the la...

How do I retrieve specific attributes of a relationship/collection?

Hi All, Is there a good way to retrieve all of a specific attribute from a relationship/collection? For instance, I want a list of all the names of a person's cars. Obviously I can't do the following: Person.Cars.Name(s) ...but does something of that nature exist in ruby (or is there an ActiveRecord helper method) that handles that?...

How do I "fake" C# style attributes in Ruby?

EDIT: I slightly changed the spec, to better match what I imagined this to do. Well, I don't really want to fake C# attributes, I want to one-up-them and support AOP as well. Given the program: class Object def Object.profile # magic code here end end class Foo # This is the fake attribute, it profiles a single method....

Managing trace code in ruby

So I use a lot of trace-code/logging when starting a new project, or debugging an existing one. I was wondering what techniques do you use to manage it, as I always end up deleting it before doing a commit, and then have to rewrite it if ever something else goes wrong. I was thinking about having a development branch with all the trace-...

How to check if a given directory exists in Ruby

I am trying to write a script which automatically checks out or updates a subverion url based on whether a specified directory exists or not, but from some reason, my code isnt working and always returns 'true' even if its false. The code: def directory_exists?(directory) return false if Dir[directory] == nil true end Can someone...

Tracking model changes in Rails, automatically

In my rails app I would like to track who changes my model and update a field on the model's table to reflect. So, for example we have: class Foo < ActiveRecord::Base before_create :set_creator belongs_to :creator, :class_name => "User" protected def set_creator # no access to session[:user_id] here... end end Wh...

How do I wrap link_to around some html ruby code?

How do I wrap a link around view code? I can't figure out how to pass multiple lines with ruby code to a single link_to method. The result I am looking for is that you click the column and get the show page: <div class="subcolumns"> <div class="c25l"> <div class="subcl"> <%= image_tag album.photo.media.url(:thumb), :class...

Selenium Ruby Reporting

I'm trying to set the environment for testing using Selenium and selenium-client gem. I prefer unit test style over RSpec style of tests. Do I have to build my own system for reporting then? How can I add exception handling without having begin-rescue-end in each test? Is there any way to do that using mixins? ...

How to use QTP to test the application which operates in citrix of Remote Machine?

When i tried recording using QTP, every thing goes well till the application sign in. i.e it gets upto the user Id and password entry, But QTP fails to recognise afterthat. Is there any way to handle this? Application is to be invoked using Citirx, in VPN. ...

Ruby on Rails: Editor for backend of the web application.

What editor can you suggest to integrate with the backend of the web app I'm currently developing? I want to allow my trusted users to add articles that would be visible on the frontend. It should have some kind of markup language (to make basic customisation - lists, bold...) and if possible also the option to upload images. ...

Nicely formatting output to console, specifying number of tabs

I am generating a script that is outputting information to the console. The information is some kind of statistic with a value. So much like a hash. So one value's name may be 8 characters long and another is 3. when I am looping through outputting the information with two \t some of the columns aren't aligned correctly. So for example...

ClassName to class_name

Hi, I'm sure this is an easy one for you geeks: Say I have a String "ThisIsMyString" and I want to format it like "this_is_my_string" using Ruby. How do I do that? Matt ...

How do I update a has_and_belongs_to_many collection RESTfully?

I have two scaffold-generated Models, student and class. They have a many-to-many relationship implemented with has_and_belongs_to_many. I'd like to be able to change which classes a student is in as well as which students are taking each class. That is, I want to modify a student's classes variable (adding and removing items from it) ...

Financial Charts / Graphs in Ruby or Python

What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart. http://en.wikipedia.org/wiki/Open-high-low-close_chart (but I don't need the moving average or Bol...

running ruby as a windows exe program

can we use our Ruby code to generate a Windows executable program, is it possible even if one of the required libraries is not from the stranded Ruby (like Qt or MySql) ??? ...

Where do I put my ruby program on mac when opening with terminal.

I'm following this guide: http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_01/programs.html and I'm trying to create my first ruby program. So I wrote it in a text editor, but now I dont know how to open through terminal. Rather, where should I be saving the program to (directory). Thanks! (I'm new to programming on mac) :( ...

How do I force RAILS_ENV in a rake task?

I have this little rake task: namespace :db do namespace :test do task :reset do ENV['RAILS_ENV'] = "test" Rake::Task['db:drop'].invoke Rake::Task['db:create'].invoke Rake::Task['db:migrate'].invoke end end end Now, when I execute, it will ignore the RAILS_ENV I tried to hard-code. How do I mak...