ruby

hash as def argument

Is the following possible in any way? I keep running into a odd number list for Hash def thores_hammer(bling) hammer_bling = { bling } end thores_hammer :rubys => 5, :emeralds => 5, :souls => 333 Thanks ahead of time. ...

Traverse xml structure to determine if a certain text node exists

Alright I have an xml document that looks something like this: <xml> <list> <partner> <name>Some Name</name> <status>active</status> <id>0</id> </partner> <partner> <name>Another Name</name> <status>active</status> <id>1</id> </partner> </list> </xml> I ...

Ruby on Rails / Yellow Maps For Ruby Plugin woes...

Okay I've read through the plugin comments and the docs as well and I have yet to come up with an answer as to how to do this. Here's my problem I want to use the :info_window_tabs and the :icon option, but I don't know what format to pass my information in. According to the documentation the following code should be correct. Here's my c...

Ruby Fails to load a DLL

Hi... I m using ruby 1.8.6 on Windows.. I m extending Ruby with C. that is i want to load a DLL into Ruby.. but Ruby fails load my Dll.. i use visual studio.net command Prompt. I integrate my dll namely prov.dll into C program namely pro1.c afterthat i call those c functions through ruby . D:\ruby_extend\pronmake>irb irb(main):00...

Creating nice pdfs with ruby

I would like to create pdfs with ruby. One special need is embedding a picture into text (or a textblock), which means I need to be able to let the text flow around the image. E.g. the image should be in the rigth upper corner and the text should start left of the image and continue after the image by using the whole width of the page. H...

Convert an array of integers into an array of strings in Ruby?

I have an array: int_array = [11,12] I need to convert it into str_array = ['11','12'] I'm new to this technology ...

Gems slowing down Rails test startup, can I selectively disable these?

I have a terrible Rails test startup time. When running a single functional test that may take 2 seconds to run, the total time from execution to returning to the command line could be up to 10-15 seconds. There are two gems I know are definitely getting in the way. A Facebook and Flickr gem (Facebooker, Flickraw). Facebooker will al...

Having some trouble getting my classes to work together.

I am working on a simple ruby assignment and I am getting and internal server error. I am assuming it is in how I am tying my classes together. EDIT: I updated it and now I am just not inserting to the database. The point of issue is where I call "result = @dbh.query(query)" This is my first page: #!/usr/local/bin/ruby require 'cgi...

Rails: Generating Tables based on groups of related database records

I have a collection of records in my database that I want to print out to separate tables based on the record date. So I already have the following (in Haml, fyi): %table %tr %th Name %th Type %th Total Hits - for record in @records %tr{ :class => cycle('odd','even') } %td= record.name %td= record.target...

Infinity, ActiveRecord and MySQL: storage and comparison

I have user input strings specifying the cost of an event (eg: "$4 for non-members"). I am trying to parse out the upper (and lower) bound of the cost (in the example, upper == lower == 4.00). Suppose that a given string cannot be parsed (maybe it's blank). In this case, I want to be able to store in the database that the maximum cost ...

Why is Ruby BigDecimal returning a weird value?

Hi, I am writing code that will deal with currencies, charges, etc.. I am going to use the BigDecimal class for math & storage. We ran into something weird with it, however. Using this statement: 1876.8 == BigDecimal('1876.8') it returns false. If I run those values through a formatting string "%.13f" I get: "%.20f" % 1876.8 => ...

Problem installing googlecharts gem?

I am trying to use the googlecharts gem to create some quick charts. Here are the rubyforge and github sites: http://googlecharts.rubyforge.org/ http://github.com/mattetti/googlecharts/tree/master After installing, I keep getting an error saying "no such file to load -- googlecharts" even though when I do a "gem list", the gem is list...

Is it possible to run Ruby on Rails with Ruby 1.9x?

If so, how? When you go to http://rubyonrails.org/download, it says: We recommend Ruby 1.8.7 for use with Rails. Ruby 1.8.6, 1.8.5, 1.8.4 and 1.8.2 are still usable too, but version 1.8.3 is not. ...

Using Dictionary.app’s thesaurus function programmatically on OSX (preferably via Ruby)

I need to write a Ruby method that takes a word, runs it through OS 10.5’s Dictionary.app’s thesaurus function, and returns alternative words. If the Ruby method ends up calling the command-line, that’s fine; I just need to be able to do it programmatically from Ruby. After looking through Ruby OSA, I realize that the Dictionary is acc...

Convincing others of Ruby over Python and PHP

G'day folks. I'm trying to introduce Ruby at work, and a few people are interested. However, I've been asked to present the benefits of Ruby over Python and PHP. I've broken this down into 2 parts: 1) show Python and Ruby's advantages over PHP; 2) show Ruby's advantages over Python. The first is easy. I'll explain things like: Everyt...

What is the best way to remap a Hash in Ruby?

Is there a simple way of remapping a hash in ruby the following way: from: {:name => "foo", :value => "bar"} to: {"foo" => "bar"} Preferably in a way that makes it simple to do this operation while iterating over an array of this type of hashes: from: [{:name => "foo", :value => "bar"}, {:name => "foo2", :value => "bar2"}] to:...

CSS/HSS Parser in Treetop and Nested Stylesheet Rules

I'm new to Treetop and attempting to write a CSS/HSS parser. HSS augments the basic functionality of CSS with nested styles, variables and a kind of mixin functionality. I'm pretty close - the parser can handle CSS - but I fall down when it comes to implementing a style within a style. e.g: #rule #one { #two { color: red; } c...

After you download an open-source Rails project, do you have to db:migrate?

This is probably a stupidly easy question for a Rails person but is causing me no end of confusion. I downloaded several open source Rails projects but am not able to run them. Usually, are you supposed to do a db:migrate before you try to run a Rails project? I thought they were supposed to just run. ...

How can I collapse this very repetitive Ruby/Rails code?

I've got two small structural issues that I'm not sure how to handle given my relative newbie-ness with RoR. First issue: In one of my views, I have code that looks like this: <ul style="list-style-type: circle"> <li><%= @apples.size %> apples</li> <li><%= @oranges.size %> oranges</li> <li><%= @bananas.size %> bananas</li> <li>...

What is the ruby equivalent of python's getattr

I am new to rails and trying to do a little refactoring (putting a partial renderer that lists titles in app/views/shared ) The renderer shows the dates along with the titles. However different users of the renderer use different dates. Part way through refactoring I have title_date = list_titles.created_on For the other user of the r...