ruby

How do I skip certain columns when parsing a text file with Ruby?

I have to parse a tab-delimited text file with Ruby to extract some data from it. For some unknown reason some columns aren't used and are just essentially spacers; I'd like to ignore these columns since I don't need their output (however I can't just ignore all empty columns since some legitimate columns have empty values). I know the...

Best practice for Rails App to run a long task in the background?

I have a Rails application that unfortunately after a request to a controller, has to do some crunching that takes awhile. What are the best practices in Rails for providing feedback or progress on a long running task or request? These controller methods usually last 60+ seconds. I'm not concerned with the client side... I was plann...

limitations of :finder_sql

In a rails app, I using the :finder_sql option in a has_many declaration. The rails docs say that when I do this, "find_in_collection is not added." What does this mean? ...

Rails: Best practice for model dependency class locations?

I have a rails app moving along fairly well, but the fact that I'm doing this myself means that some poor sod is eventually going to see this and say, "What the hell were you thinking? Why did you put this here?!?!" Where is that poor, sorry soul going to expect to see a series of classes that aren't used by anything but a single model...

What's the best way to learn more advanced Ruby OOP constructs?

So I've become a reasonably proficient Rails developer, and I'm finding that my bottleneck is now my lack of understanding of more complex Ruby constructs. I'm trying to build some plugins, and looking at some complex ones out there, their OOP wizardry is Greek to me. (I never had much formal OOP training so that's part of the problem.) ...

Rails ActiveRecord: Automatically Alias/Append Suffix?

I've got a legacy database with a bunch of idiotically named columns like: some_field_c some_other_field_c a_third_field_c I would very much like to make a Rails ActiveRecord sub-class that automatically aliases these attributes to their name minus the underscore and "c". However, when I tried: attributes.each_key do | key | name =...

Which is easier for beginners: RubyCocoa or ObjC/Cocoa

I've heard a few debates in the past over which is more mature: RubyCocoa or Obj-C/Cocoa... but I have felt that the answers jet right over the "newbie" that would truly appreciate an answer. So the question is: for a total beginner, with little-to-no programming experience, is it easier to learn Ruby and explore Cocoa via the bridge (t...

Problems with RSpec and Chronic

I'm trying to use Chronic inside my non-rails project. When I try to get the specs with 'spec' I get the following error: $ spec spec/parsers/parser_english_spec.rb /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- chronic (LoadError) from /Library/Ruby/Site/1.8/rubygems/custom_requ...

Automation Script: Click on "Cancel" button on alert window by Ruby

I would like to know is there any way to select(click on) Cancel button on alert window? I used: @browser.choose_cancel_on_next_confirmation() @browser.click("//td[text() = '[email protected]']/../td//a[text()='Delete']") ...

Combined Python & Ruby extension module

I have a C extension module for Python and I want to make it available to Rubyists. The source has a number of C modules, with only one being Python-dependent. The rest depend only on each other and the standard library. I can build it with python setup.py build in the usual way. I've been experimenting with adding Ruby support using n...

How to implement an abstract class in ruby?

I know there is no concept of abstract class in ruby. But if at all it needs to be implemented, how to go about it? I tried something like... class A def self.new raise 'Doh! You are trying to instantiate an abstract class!' end end class B < A ... ... end But when I try to instantiate B, it is internally going to call A....

Using Ruby libraries and gems with a Shoes app

I am writing a little Shoes app that requires a library I wrote with my regular Ruby installation. My library uses the 'net-ssh' gem and a bunch of other Ruby libraries. When I run my library directly with regular ruby (it has its own command-line interface) like this: ruby my_lib.rb ...all is fine. But when I try to require it withi...

Handing Non-UTF8 content in my Rails application appropriately

I have a Rails application that allows users to import information from various sources using RSS feeds and such. My default encoding on the database is UTF8 and I've been receiving a lot of exceptions in regards to non-UTF8 data that is coming through the system and crashing once it hits the database. I'm to appropriately detect the n...

Rails : Retrieved Object has no attributes, and is not comparable with real

This issue is really losing me. I have a model for authentication : user. I have a model for comments : comment. I have a model that is commentable : weburl. Weburl 1..* Comment Weburl *..1 User Comment *..1 User The issue I have is not testable (my tests are all passing), and does not happen all the time. Usually it happens the sec...

How do I delete an OU with everything inside at once?

I would like to have a single LDAP command that would delete an entire OU atomically, including all children. I see there's a command for the windows command-line: Delete an Organizational Unit dsrm <OrganizationalUnitDN> [-subtree] That -subtree option deletes children too. Is there a way to do that using LDAP? Bonus points, if som...

What's the fastest way for a true sinatra(ruby/rack) after_filter?

Okay it's a simple task. After I render html to the client I want to execute a db call with information from the request. I am using sinatra because it's a lightweight microframework, but really i up for anything in ruby, if it's faster/easier(Rack?). I just want to get the url and redirect the client somewhere else based on the url...

Performance implications of using BigDecimal vs. Integer in a Rails app

How much less efficient would it be to store some fields as a BigDecimal instead of as an Integer in a Rails app? Some computation (a bunch of arithmetic) will be done with these values. Does this affect performance for Rails, the database or Ruby in general? ...

Converting binary data to string in ruby

I have a string containing byte data. How can I perform an in-place conversion to ascii string? ...

Ruby cannot find sqlite3 driver on windows

I am trying to set up Ruby on Rails on windows. I am using the Flash Rails distribution that looks pretty good, but there is an issue with sqlite3. I found the threads telling me to install version 1.2.3, which installed fine. I'm using ruby 1.9.0, and every time I try and run a script (e.g. rake db:create) that uses the database I get a...

Inserting into Set changing the order of Elements in an Array in Ruby

@search_results = Array.new duplicates = Set.new results.each { |result| @search_results.push(result) unless duplicates.add?(result[:url]) } This piece of code is garbling the order of elements in the array @search_results. Why would inserting the same element in a set and an array change the insertion order for Array? Seems like so...