ruby

PEAR alternatives in other languages

Is there a good class repository like PEAR for PHP for other languages such as Ruby or C#? If so what are they? Are they any good? ...

BlueCloth error on windows

Having a bit of a nightmare getting bluecloth to work on windows. I grabbed the gem from the site (since gem install bluecloth doesnt work). However, I can't seem to get the library to load irb(main):001:0> require 'rubygems' => false irb(main):002:0> require 'bluecloth' LoadError: no such file to load -- bluecloth_ext from C:/R...

conditional statement and assigning value in ruby

def foo;5;end # this one works if (tmp = foo) puts tmp.to_s end # why this one fails puts tmp2.to_s if (tmp2 = foo) #=> undefined local variable or method ‘tmp2’ for main:Object ...

Ruby: acts_as_tree to nested hashes (arrays of hashes)

I am trying to figure out a graceful way to "draw" out an arbitrary tree structure, defined using acts_as_tree. My ultimate goal is to convert the parent/child relationships into a nested hash that can be converted into a Yaml file. example tree: root --child --child ----subchild ----subchild ------anotherchld --child --child ----subch...

Is packaging scripts as executables a solution for comercial applications?

What happens when you package a script as an executable? Is this a good way to distribute commercial applications? I remember I read something a long time ago that when you package scripts as executables, at runtime the exe decompresses the scripts to a temporary directory where they get ran. If it's like that, than I don't think this c...

Issues POSTing XML to OAuth and Signature Invalid with Ruby OAuth Gem

[Cross-posted from the OAuth Ruby Google Group. If you couldn't help me there, don't worry bout it] I'm working on integrating a project with TripIt's OAuth API and am running into a weird issue. I authenticate fine, I store and retrieve the token/secret for a given user with no problem, I can even make GET requests to a number of serv...

Ruby Array.inject issue -- Can't see it

I am trying to store values from an array, to a hash (array value is the key, value just 0). Here is my code. Any ideas? [1, 2, 3, 4].inject({}) {|result, e| result[e] = 0} This is the error I am getting. oMethodError: undefined method `[]=' for 0:Fixnum from (irb):1 from (irb):1:in `inject' from (irb):1:in `each' ...

How to make --no-ri --no-rdoc default for gem install?

I don't use RI nor RDOC from the gems I install in my machine or in the servers I handle. (I use other means of documentation) Every gem I install comes whith ri and rdoc by default and I forget to set --no-ri --no-rdoc. Is there a way to make those 2 flags default? ...

Rails, has_many and joins

Hello! I have three models, User, Type and TypeDescription, and as you can see below, each User may have many types, but each type has only one description. So as optimization, I thought each TypeDescription should be joined with Type via JOIN in sql, so I used default_scope and defined join, and that works when I get type via Type.find...

How to enable auto compleation in Ruby's IRB

When I use Merb's built in console, I get tab auto-completion similar to a standard bash prompt. I find this useful and would like to enable it in non-merb IRB sessions. How do I get auto-completion in IRB? ...

XCode 3.2 Ruby and Python templates

Under xcode 3.2 my ObjectiveC + Python/Ruby projects can still be opened updated and compiled, but you cannot create new projects. Given that all traces of ruby and python are missing from xcode 3.2 (ie create project and add new ruby/python file), is there an easy way to get the templates installed again? I found some info about copy...

How can I make sure Ruby's Find module will always return absolute paths?

If I run the Find module with a relative directory as a parameter, the files returned by it will be relative ones. Can I do anything to make sure I always have absolute paths ? require "find" Find.find(dir) do |file| # do I need to make it absolute myself? will File#extend_path be enough? end ...

Signup or Invitation Email Verification w/o Database

I'd like to keep my database clean of stale almost-accounts, and I was thinking about making new signups and invitations put their data into the welcome email as an encrypted or hashed url. Once the link in the url is visited, the information is then added into the database as an account. Is there something that currently does this? Any ...

Net::SSH::Multi using the session.exec, how do you get the output straight away? Ruby

So I've been trying to use the Net::SSH::Multi to login to multiple machines using the via SSH, and then executing shell commands on the remote machines with session.exec("some_command"). The Code: #!/usr/bin/ruby require 'rubygems' require 'net/ssh' require 'net/ssh/multi' Net::SSH::Multi.start do |session| # Connect to remot...

How can I return a value from a thread in Ruby?

If I have the following code : threads = [] (1..5).each do |i| threads << Thread.new { `process x#{i}.bin` } end threads.each do |t| t.join # i'd like to get the output of the process command now. end What do I have to do to get the output of the process command? How could I create a custom thread so that I can accomplish this?...

Why is this running like it isn't threaded?

I'm writing a script that will ping my ip range. Here's what I have so far: lines = `ipconfig`.split("\n") thr = [] ip_line = lines.detect { |l| l=~/Ip Address/i } matcher = /\d+\.\d+\.\d+\.\d+/.match(ip_line) if matcher.length > 0 address = matcher[0] address.sub!(/\.\d+$/,"") (1 .. 254).each do |i| xaddr = address + "...

Ruby on rails: Paperclip & Ruby Mp3Info

I'm trying to upload a mp3 file (using the paperclip plugin) and then read the mp3 info (using the Mp3Info gem) right away so I can get the title, song length ect. I can successfully upload a mp3 file using paperclip, but when I try Mp3Info.open(@song.music.url), I get an error saying the file is empty. Is there a proper reference to a...

GC Not Cleaning Up (was: Tempfile Not Deleting Automatically, Ruby)

Ruby tempfile instances automatically delete their corresponding file when the references are released. However, I have one machine on which this is not the case. The code is irb> require 'tempfile' => true irb> t = Tempfile.new('test32') => #<File:/tmp/test32.27778.0> irb> exit on all of my test machines, this results in test32 getti...

How to force gem install to download the docs file as well?

I've setup the following in my ~/.gemrc file gem: --no-ri --no-rdoc so that when I do gem install some_gem, the rdocs won't get installed to not pile up my disk. But for some gem, I'ld like to install the rdocs as well. So i tried, gem install some_gem --rdoc --ri the docs doesn't get downloaded. How can I force the gem install to...

How to handle escaped characters in XPath expressions for Nokogiri

I'm using nokogiri with an xml document that looks something like this: <songs> <song> <artist>Juana Molina</artist> <album>Un Dia</album> <track>8</track> <title>Dar (Qu&#233; Dif&#237;cil)</title> <rating>5</rating> <filename>\Juana Molina\Un Dia\08 - Juana Molina - Dar (Qu&#233; Dif&#237;cil).mp3</filename> ...