ruby

Removing a gem from GemCutter

I want to delete a gem I uploaded to GemCutter. I couldn't find any commands for this. Some time ago there was a blog post stating gem deletion as an upcoming feature. I haven't seen any further official announcements about this feature. Please let me know if there is a way to do this. ...

Ruby file IO delimiters?

I am trying to parse a text file that contains a variable number of words and numbers per line, like this: foo 4.500 bar 3.00 1.3 3 foo bar How can I read the file delimited by spaces instead of newlines? Is there some way I can set the File("file.txt").foreach method to use a spaces instead of newlines as a delimiter? ...

Ruby on Rails: How would I add a link from a custom plugin to my app's navigation?

I'm trying to add a navigation link from a plugin that I made without altering the main app files. For example, say that I have this: app/views/shared/_navigation.html.erb <ul id="navigation"> <li><a href="#">Nav link A</a></li> <li><a href="#">Nav link B</a></li> <li><a href="#">Nav link C</a></li> </ul> If I have a custom plugin...

Trying to return various models with Ruby Activescaffold find on models with inheritance

class Promotion def self.get_todays_promotions # Promotion is a parent model, having child models e.g. # DiscountPromotion, VoucherPromotion, etc. # they all use a single table called promotions # (and having 'type' field explaining which model they belong to) promotions = self.find(:all, :conditions => [Promotion....

Using yield inside define_method in Ruby

Is it possible to make yield keyword work inside a block given to define_method? Simple example: class Test define_method :test do |&b| puts b # => #<Proc:...> yield end end Test.new.test { puts "Hi!" } This code produces following error in both Ruby 1.8.7 and 1.9.0: test.rb:4:in `test': no block given (LocalJump...

Copying files to USB disc with Ruby

How can I copy files to a USB stick with Ruby (in Windows)? So far I have tried to identify the path of the USB stick, with the idea of using FileUtils to copy the files. However, I haven't been able to identify the path. Anyone know how to do this, or suggest an alternative approach. Thanks Edit: I've found a solution. Windows in...

Ruby - Changing the date part of a Time instance

I have a Time instance curr_time with the value of Time.now and another String target_date with the value, say, "Apr 17, 2010". How do I get the date part in the variable curr_time change to the value of target_date ? >> curr_time => Sun Feb 21 23:37:27 +0530 2010 >> target_date => "Apr 17, 2010" I want curr_time to change like this:...

$" surviving between calls

I have an odd situation where $" seems to be surviving between calls, but nothing else does. It's returning properly the first call, and fail each additional request. This should be global information, so It won't work just to put it in a session. The comments show what logging returns, but my experience with "FileImport.installed_for...

What is the best way to determine the count of records that will be returned by a query with rufus-tokyo?

I would like to determine the number of records that a query on a Tokyo Cabinet Table will return before I run the query. I am using the rufus-tokyo Ruby gem as my interface. What is the best way to do this? ...

How does Ruby compare strings?

Hi, maybe someone knows the technical answer to the following behaviour: s = "hello world!" s == s.upcase # =>false, because "hello world!" != "HELLO WORLD!" s == s.upcase! #=>true, because s is changed before comparison? Thanks in advance, Mathias ...

ROR very slow in development while production works fine

I have one rubyonrails app that turned really slow in development mode. Everything is fine in production, but even a simple "hello world" takes seconds in dev. I checked the session store and every possible reason i found on the net, but I didn't find the problem. Am I missing something that is common knowledge? "Completed in 1657ms (Vie...

SQLite-like alternative for MongoDB?

I'm looking for a document-oriented db with a Ruby API that has SQLite-like properties: self-contained, serverless, zero-configuration. Are there light alternatives to MongoDB or CouchDB? Is RDDB a possibility? If not, what are the best paths to walk then? ...

RubyGems - my system can't seem to find any remote gems to install

RubyGems newbie here, trying to install the 'less' gem. I type 'sudo gem install less' as instructed at http://lesscss.org/, and I get the following error: ERROR: While executing gem ... (Gem::GemNotFoundException) Could not find less (> 0) in any repository Alright, so I figure maybe I just need to update RubyGems. Trying 'gem...

Why does Ruby expose symbols?

I was just wondering why Ruby exposes symbols for explicit use - isn't that the sort of optimisation that's usually handled by the interpreter / compiler? Thanks for any insight :) ...

problem using accept_nested_attributes with polymorphic relations and inheritance

Having this mix of polymorphism and inhertiance, I encounter some weird behaviour: Migration class CreateCommons < ActiveRecord::Migration def self.up create_table :commons do |t| t.string :name t.string :configurable_type t.integer :configurable_id end create_table :specifics do |t| t.integer :nu...

How can I use a variable as a variable name in Ruby?

How can I make the code below work, so that both puts display 1? video = [] name = "video" name[0] = 1 puts name[0] #gives me 1 puts video[0] #gives me nil ...

the best way to store my statistics (ruby)

I want to display some statistics of data stored in array of arrays. I have three categories (video,article,webinar) but it could expand later on. The structure of statistics per category will be almost the same. Like: total number of videos, last date when added new record in category, etc. So far I can think of a hash of an array to s...

Splitting unicode (I think) using .split in ruby

Hi all- I am currently scraping an rss feed from last.fm and the title attribute looks like it has a unicode "-" that comes up as \u2013 on firebug. Here is the feed for those that are curious: http://ws.audioscrobbler.com/2.0/user/rj/recenttracks.rss When I write something like this feedentry.title.split('-') it won't find the un...

How to gsub slash "/" with back slash and slash "\/" in ruby

I try to modify "/foo/bar/dir" -> "\/foo\/bar\/dir" before execute it in command line. I test by using gsub in irb the result is x = "/foo/bar/dir" x.gsub("/","\\\/") => "\\\/foo\\\/bar\\\/dir" x.gsub("/","\/") => "/foo/bar/dir" Is it possible to replace "/" with "\/" by gsub ? Source of problems is I try to execute "string i...

Ruby: Resumable functions with arguments

I want a function that keeps local state in Ruby. Each time I call the function I want to return a result that depends both on a calling argument and on the function's stored state. Here's a simple example: def inc_mult(factor) @state ||= 0 # initialize the state the first time. @state += 1 # adjust the internal state. factor...