ruby

Ruby, Generate a random hex color

How can I generate a random hex color with ruby? ...

Can I use rspec mocks to stub out version constants?

I've got code that only needs to run on a certain version of ActiveRecord (a workaround for a bug on old AR libraries). This code tests the values of ActiveRecord::VERSION constants to see if it needs to be run. Is there a way to mock out those constants in rspec so I can test that code path without relying on having the right ActiveRec...

Using the xmpp4r Ruby gem, how can I synchronously discover if a contact is online?

I'm new to XMPP and the xmpp4r library, so please forgive my noob question if this is obviously documented somewhere. What's the most straightforward way, in a synchronous manner, to find out if a given JID is online? (so that I can call something like is_online?(jid) in an if statement) My details: I'm writing a Sinatra app that wil...

RoR - make links clickable that show up in a user comment

I am looking for a Ruby script that takes a piece of text, and makes any links click-able that show up in it... Does anyone have something like this? For example, if I wrote a comment and said "Come check out my site at http://www.example.com", then the link would be click-able like an html tag. Thanks, Josh ...

Is there a "Code Complete" book for Ruby?

Hi there, I began reading the book "Code Complete" 2nd edition, but stopped reading when I noticed most of the solutions were easily solvable in Ruby with Ruby idioms. Is there a similar book for Ruby? Here's the version that I started reading: http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670 ...

Ruby installer on Windows 7 64-bit machine

Can anyone please help me where to find Ruby 64-bit installer to be installed on Windows 7 or can I install 32-bit ruby 1.8.6 or 1.9 installers(only one) on a 64-bit machine without any problem?. Any recommendations or links for documentation would be appreciated. Thanks in advance. ...

Parsing Text Files and Sorting in Ruby

I am somewhat new to Ruby and I would appreciate some direction in solving the problem which I will now describe. I would like to write a Ruby program which can parse 3 separate text files each of which contain different delimiters and then sort them according to certain criteria. Can someone please point me in the right direction? ...

Ruby library/gem for game graphics?

I am creating a simple Blackjack game in Ruby, and I have finished all the game logic stuff (finally!) and currently have it running through the command line. It is all working, so now I need a library or gem that will make the whole graphics side of things easier. Any ideas? Thanks. ...

Wrapping C structs with SWIG

I have C header file containing the following type definition: // example.h typedef struct Vertex { int color; } Vertex; I try to wrap this struct with SWIG, but apparently I am doing something wrong. My SWIG interface file looks like // example.i %module example %inline %{ #include "example.h" } But if I copy the contents of my ...

Key based authenication with net-sftp in Ruby

Hello, I want to be able to use SFTP to login into a number of servers and download certain files to help debug issues as and when they arise. While we could use a client, we wanted to start automating the process to streamline everything. My first attempt looks something like this: def download(files_to_download, destination_directo...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an light among netbeans and aptana? ...

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I've a project with two extension modules, foo.so and bar.so which currently live in their own subdirectories like so: myproject/ext/foo/extconf.rb myproject/ext/foo/foo.c myproject/ext/foo/foo.h myproject...

Ordering a hash to xml: Rails

I'm building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml ...

What is the shortest way to insert 2 dashes into this string with ruby?

Here's the string: 04046955104021109 I need it to be formatted like so: 040469551-0402-1109 What's the shortest/most efficient way to do that with ruby? ...

RubyCAS-Client question: Rails

I've installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It's working, but I'd like to remove the ?ticket= in the url. Is this possible? ...

Need some input on how to build a large scale text replacement system

My Rails app deals a lot with data from third-party APIs (specifically UPS, FedEx, DHL, etc). What I'd like to do is whenever that data comes in, replace certain phrases with customized phrases. Example: "On FedEx vehicle for delivery" (which we get from the FedEx API), I'd like to replace with "Out for Delivery." Is it best to replac...

Ruby Geolocation Gem/Plugins

What are the available (best) ruby IP-based geolocation gem/plugins? How do they compare to one another in terms of functionality, performance and ease of use (e.g. do they interact with a web service, or require a separate database, etc.) ? I'm hoping anyone that has used some can share their experience and give recommendations. ...

Searchlogic question

The functionality I'm looking for: I have a form that will search my 'Proposal' model. I want the form to contain a select box and display the categories I have. Now, 'category' is merely a column in my 'Proposal' Model, so the following code from railscasts does not work (as it assumes a category table and use of category_id) <%=...

Top 3 improvements that Ruby offers?

Back when I was learning HTML, I loved how easy it to build pages and arrange everything just the way I wanted using tables. Then I moved to CSS and learned that you could quickly swap designs without recoding your page. With just a few CSS changes your HTML designs could go from one theme to another and any element could become any oth...

Why would the Net::LDAP gem prevent tests from running?

I have installed the ruby-net-ldap gem version 0.0.4 on my OS X (Snow Leopard) system. When I include the line... config.gem('ruby-net-ldap') in environment.rb, my tests won't run and I get this error... Missing these required gems: ruby-net-ldap You're running: ruby 1.8.6.0 at /usr/local/bin/ruby rubygems 1.3.5 at /Users/et...