ruby

Ruby specific thread semantics

I just ran across an issue that probably exposes my ignorance of common threading semantics. I assumed that the following ruby was valid: d = Thread.new{ Thread.stop } d.join That is, I thought that joining a stopped thread would simply be a NOP - the thread is already finished, so join should return immediately. Instead, Ruby-...

How to remove a remote source from gem remote sources

I have added gemcutter.org to my Rubygems sources, and now I do not know how to remove it. $ gem sources *** CURRENT SOURCES *** http://gemcutter.org http://gems.rubyforge.org/ ...

Rails routing with date and has many

I've got the following setup: map.resources :articles map.resources :users, :has_many => [:articles] Which is fine as I can do /users/2/articles to get a list of articles by a given user. I also have a route setup to do: map.connect 'articles/month/:month/:year', :controller => 'articles', :action => 'index' Which works for find...

linux like behavior in windows shell - running ruby without "ruby" appended to the command?

This is probably a really silly question bu tI can't seem to find an answer since I'm apparently failing on keywords. You know how you can run commands from the commandline in linux if you put a line on the top of your .rb file so you don't have to type ruby myfile.rb all the time and can just do ./myfile.rb ? Is it possible to have the...

Edit crontab programmatically and force the daemon to refresh

Hi, I'm trying to write a web frontend for Crontab in Ruby using the excellent CronEdit gem. I went through Dillon Cron's crontab source code and found that it updates a particular file so that the daemon will refresh the cron list during the next sweep. In man crontab for VixieCron, it says: Additionally, cron checks each minute to ...

merging array items in ruby

Given an array of arrays [["B", "C", "E", "F"], ["A", "B", "C", "D"], ["G"]] What is the simplest way to merge the array items that contain members that are shared by any two or more arrays items. For example the above should be [["A", "B", "C", "D","E", "F"], ["G"]] since "B" and "C" are shared by the first and second array items. He...

How to concatenate a Hash to URL parameters?

Hi all, a quick Ruby question for you: params = {:q => "A query",:foo => "bar",:nasty => "Schrödinger's cat"} p do_it(params) => q=A%20query&foo=bar&nasty=Schr%C3%B6dinger%27s+cat (I think ö encodes like that, excuse me if its wrong) Is there a simpler way to do this than the following?: def do_it(params) out = [] params.each_pai...

Checking emptiness of an element in hpricot

Let's say this is the location element: <.location>blah...<./location> It can be empty like this: <.location/> Is there a way to detect the backslash in the empty element in order to not return it? ...

How do I integrate SAML into my Rails Application?

I have a rails app that is currently an affiliate site with my customer's SSO Identity Provider. Currently it uses the CA SiteMinder Affiliate Agent, which is an apache module. The underlying SSO architecture is abstracted away and my Rails app only has to parse and HTTP Header to receive the values from my customer's Identity Server. ...

Compare sequential last elements in ruby array

I have an array that contains values that I'm working on (in a specific order) something like the following: myArray = [3,6,5,6,2,1] I need to evaluate the elements in the array and determine the number of the elements to copy. The rules are: I need to copy the elements where the sum of those elements is not greater than the previous...

printing a ruby block

I have a method that takes a block. Obviously I don't know what is going to be passed in and for bizarre reasons that I won't go into here I want to print the contents of the block. Is there a way to do this? ...

Problem with Ruby Gem and Sanitize

Hi, I'm trying to install the Ruby gem sanitize. I've already installed nokogiri: >gem list nokogiri *** LOCAL GEMS *** nokogiri (1.4.0) but when I try and install sanitize I get the following error: >gem install rgrove-sanitize ERROR: Error installing rgrove-sanitize: rgrove-sanitize requires nokogiri (~> 1.3.3, runtime) ...

Should I use inheritance for a Ruby project involving common attributes and differing methods?

I'm learning Ruby and working on my first real project. The program will receive a data structure and needs to reproduce the information contained that structure in various text formats. All of the different output types rely on the same set underlying attributes (about 40 of them) and the same set of common functions (about 10 of them);...

Convert XML into a Dataset

I'm trying to convert an XML document into a dataset that I can import into a database (like SQLite or MySQL) that I can query from. It's an XML file that holds most of the stuff in attributes. This is part of a Rails project so I'm very inclined to use Ruby (and that's the language I'm most comfortable with at the moment). I'm not sur...

Which Twitter API Library for Ruby do you recommend?

What is the best Twitter API Library for Ruby? I want to do simple things like: search for specifics keywords for a date range start following people tweet messages How can I do these things with the library you recommend? ...

Listing the Accessors in a Ruby Class

Is there a simple way to list the accessors/readers that have been set in a Ruby Class? class Test attr_reader :one, :two def initialize # Do something end def three end end Test.new => [one,two] What I'm really trying to do is to allow initialize to accept a Hash with any number of attributes in, but only commit the ...

Ruby Proc object as public member variable doesn't work?

I am a bit of a Ruby noob when it comes to the more advanced features. Currently I am experiencing with Proc objects. Can someone tell me what is wrong with this code sample? class Tester @printer = Proc.new do |text| puts text end attr_accessor :printer end t = Tester.new t.printer.call("Hello!") It gives me the following ...

Strange ruby behaviour with __FILE__ constant?

Hi I have been testing some very basic things in ruby and discover the following. If i put in a file called xxxx.rb in this path "C:\Documents and Settings\Desktop\xxxx.rb" puts __FILE__ and invoke this ruby file in a command line WITHOUT preceding ruby the output is the following C:/Documents and Settings/Desktop/xxxx.rb but i...

Ruby require problem

I'm trying to get the sanitize gem up and running. I've installed sanitize and nokogiri 1.3.3 as required, but when I try and use it in my application_helper.rb: require 'rubygems' require 'sanitize' I get the error: MissingSourceFile no such file to load -- sanitize RAILS_ROOT: C:/Ruby/GWS (stack trace) This error occurred while ...

How to (better) check for element existence within multidimensional array?

How do I avoid doing this? if boolean_array[day] && boolean_array[day][slot] && boolean_array[day][slot].zero? # boolean_array[day][slot] element exists end ...