ruby

gem update sqlite3-ruby failed on Windows 7

This is the command I gave in command prompt: gem install sqlite3-ruby > sqlite3-ruby.txt This is the content of sqlite3-ruby.txt Successfully installed sqlite3-ruby-1.2.5-x86-mswin32 1 gem installed Installing ri documentation for sqlite3-ruby-1.2.5-x86-mswin32... Installing RDoc documentation for sqlite3-ruby-1.2.5-x86-msw...

how do you assert an exception from another ruby module is thrown? (using assert_throws)

I'm trying to write code like this: assert_throws(:ExtractionFailed) { unit.extract_from('5 x 2005')} ExtractionFailed is a trivial subclass of Exception, and under test/unit, I'm trying to assert that it is thrown when I call unit.extract_from(... bad data...) I've moved ExtractionFailed into the SemanticText module, so now test/un...

Converting upper-case string into title-case using Ruby

Hi, all. I'm trying to convert an all-uppercase string in Ruby into a lower case one, but with each word's first character being upper case. Example: convert "MY STRING HERE" to "My String Here". I know I can use the .downcase method, but that would make everything lower case ("my string here"). I'm scanning all lines in a file and d...

Rails ActiveRecord Transaction does not finish

Hi everyone, I have a Transaction for a batch insert/update block and all of sudden it stopped working. The are no errors or exception risen and it seems like Rails stops just before the end of the Transaction blog so the methods does not return. I restarted both MySQL and the system but still. ...

quick/fast integer multiplication in ruby?

Hi there, I am trying to make a quick/efficient Mandelbrot implementation in Ruby. A long long time ago, one way to speed it up was using fixed point integers instead of floats. So i made the following benchmark, comparing float and integer raising to a square, using multiplication or square ** operand. require 'benchmark' Benchmark....

Problem with Ruby AWS - Please help!

I'm using the Ruby-AWS gem to interact with Amazon. I was testing it out in my controller and it worked fine, but when I moved the code into my Model, it isn't correctly parsing the data back from amazon. For instance, in my controller @items[0].medium_image.url = "http://ecx.images-amazon.com/images/I/61YIGdgh86L._SL160_.jpg" But in...

Drying up code for two models with similar data types

Lets say I have a wine and beer model/controller along with a wine_review and beer_review model with a has many relationship. Each table has near identical data types, for example, wine_review and beer_review each has a rating and comment column. Wine and beer each, have names. How can I dry up my code so they can both share the same ...

Ruby: creating a simple application in Qt

I'm trying to create a simple application, written in Ruby via Qt. I designed a form (MainForm) in a Qt Designer and translated it via rbuic4 to the Ruby code representation. The pure untouched result has four methods, and looks like this: =begin ** Form generated from reading ui file 'stackover.ui' ** ** Created: Р’С‚ 24. РЅРѕСЏ 21:15:...

Better Way to Remove Blank Lines After Nokogiri Node Removal

Perhaps this is nitpicky, but I have to ask. I'm using Nokogiri to parse XML, remove certain tags, and write over the original file with the results. Using .remove leaves blank lines in the XML. I'm currently using a regex to get rid of the blank lines. Is there some built-in Nokogiri method I should be using? Here's what I have: requir...

What exactly is is this in ruby: `&:capitalize`

I just read this answer http://stackoverflow.com/questions/1791639/regular-expression-in-ruby-to-convert-uppercase-title-into-lowercase/1792102#1792102. There is the following line of code "abc".split(/(\W)/).map(&:capitalize).join What exactly is &:capitalize? Before I had put this into irb myself, I would have told you, it's not va...

Using Hash Tables as function inputs

I am working in a group that is writing some APIs for tools that we are using in Ruby. When writing API methods, many of my team mates use hash tables as the method's only parameter while I write my methods with each value specified. For example, a class Apple defined as: class Apple @commonName @volume @color end I would inst...

Ruby: just-in-time gem installation?

Would it be possible to override the default "require" by adding automatic download-and-install code for any missing includes (provided that the missing include is published as a ruby gem). Which would not work in situations where Ruby is not interfaced with a shell. But still I think it would be an interesting idea. Is there such a me...

How to use ruby thin with CGI scripts?

I've written some ruby CGI scripts (using the Ruby CGI class) that I serve from my production server using lighttpd. I want to test them on my development server using thin. Basically, I want to drop all my CGI scripts in a directory and start thin in that directory. Then, any requests to http://localhost:3000/<script> should just exe...

Help with Wx::HtmlListBox.hit_test (wxRuby, but should be similar to C++/Py/etc)

Hi. I am having some trouble with using hit test for htmllistbox in wxRuby. It seems to return some odd results, even when this is not over the control. The context is in a context menu event. I am able to use hit_test with ListCtrl, but I can't seem to get it to work. case when (ht = @htmllist.hit_test(@htmllist.screen_to_client ev...

Can Ruby be used for UI based Windows apps?

I'm sorry if this question is noob-ish but I'm not having much luck with Google. Can Ruby be used for UI based Windows apps? I'm not looking for a Rails app, just Ruby. Thanks ...

Rails and Javascript minifier and aggregator

Hi, I am starting a new rails project and is there any rails plug in I can use that will minify my javascript and combine it into 1 file? I would imagine there might be a rake task for this. What would be used for this in rails? Cheers Paul ...

Uploaded file char-set conversion with Ruby

I have an application where we're having our clients upload a csv file to our server. We then process and put the data from the csv into our database. We're running into some issues with char-sets especially when we're dealing with JSON, in particular some non-converted UTF-8 characters are breaking IE on JSON responses. Is there a way ...

Generating documentation for Ruby

What do you use for generating documentation for your Ruby files? ...

Sinatra on Rack under Passenger returning 0-byte pages

I'm trying to write a Sinatra app that will run on a shared Passenger server. For now, I'd be happy just getting a "hello world", but something isn't working quite right. I have: config.ru require 'vendor/sinatra-lib/sinatra.rb' set :environment, :production disable :run require 'myapp.rb' run Sinatra::Application myapp.rb get '/...

Why would yaml be unavailable in production?

On my OS X development system: $ ruby --version ruby 1.8.6 (2007-03-13 patchlevel 0) [universal-darwin8.0] $ script/console Loading development environment (Rails 2.3.4) >> require 'yaml' => [] On CentOS 5.3 production system: $ script/console production Loading production environment (Rails 2.3.4) /opt/ruby-enterprise-1.8.7-2009.10...