ruby

Ruby Facets 2.9.0 work with Ruby 1.9.2?

Does Ruby Facets 2.9.0 work with Ruby 1.9.2? Cause I can't get rekey method to work: http://rubyworks.github.com/facets/doc/api/core/Hash.html#method-i-rekey ...

Getting started with Authlogic -- is this what I am looking for?

I'm looking to build an application that handles authentication and authorization for a variety of smaller apps that may or may not be rails applications (e.g. some with sinatra, some with non-ruby frameworks, etc). These applications will be on separate domains. Can I do this with Authlogic? I do not want to setup a rails application f...

OAuth Provider Service and Rails 3

I am trying to look into setting up an OAuth Provider Server with Rails 3 but can't seem to find anything out there to accomplish this. I am also a newb when it comes to oauth, so excuse my ignorance. When setting up an oauth server do I need to already have an oauth account at somewhere like agree2.com? Or can I just use my own serve...

Ruby on rails: Devise, want to add invite code?

Hi, I would like to add an invite_code requirement for users to sign up. Ie. in addition to requiring them to specify an email/password combo, I want an additional field :invite_code. This is a temporary fix so that non-wanted users cannot login during a given alpha period. I'm confused since Devise doesn't add controllers. I'm sort o...

Disabling ActiveModel callbacks

I published an article on disabling ActiveModel callbacks, but I’m not completely sure this is the prettiest way to do something like this. Mongoid::Timestamps adds a before save callback that updates the updated_at field. Let's say I don't want that in some cases and I disable the callback like this: class User # I'm using Mongoid, ...

Installing rmagick on Ubuntu

Hey all - I'm trying to get RMagick setup on Ubuntu 10.04. Looked here but had no joy. I even compiled and installed ImageMagick from source, but the instructions here still didn't help me when I try to install RMagick using RubyGems. I got this error: carcher@carcher-laptop:~/Code/temp/RMagick-2.13.1$ sudo gem install rmagick Buildin...

Parsing arguments with defaults and flags.

I've got a ruby bin with some arguments, namely -s, -c and -r (short for scrape, create and run). Now I'd like to set some defaults to scrape and create ('.' in both cases), but if I use :default in trollop, I can't check wherever that argument is set or not. project --scrape should be equivalent to project --scrape . how to achiev...

When and when not to stub/mock a test

I am making a concerted effort to wrap my head around Rspec in order to move towards more of a TDD/BDD development pattern. However, I'm a long way off and struggling with some of the fundamentals: Like, when exactly should I be using mocks/stubs and when shouldn't I? Take for example this scenario: I have a Site model that has_many :b...

Textmate cucumber bundle issues - 'Run Feature' producing errors.

From a cucumber feature file when I go to 'Run features' Im getting the error below in the popup box that appears. How do I fix this? /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require': no such file to load -- /Users/richie/Projects/i9/Tornelo/.bundle/environment (LoadError) from /Library/Ruby/Site/1.8/ru...

security issue running jruby on tomcat6

i deployed a jruby/rails app to tomcat6 through a warbler-built war. system is ubuntu 8, running tomcat6. when i try to start the app, i get the following stack trace Sep 13, 2010 7:57:24 PM org.apache.catalina.core.ApplicationContext log SEVERE: Application Error java.security.AccessControlException: access denied (java.ut...

Ruby/Ruby on Rails vs PHP

We do not get much projects in Ruby, we are so far focused only on PHP. As a web development agency are we missing an important channel of revenue due to our unopened nature with Ruby and Ruby on Rails? If we start doing some local projects, learn Ruby, is is possible to open another revenue channel? Is it wise to ask PHP developers to l...

Trace the code in Ruby?

Is there a good way to run a script and see all the steps: Which code is executed Which file the code is in What it returns The error messages This would be a good way to learn how an open source project is working. Aren't there solutions like this for Ruby? Eg. require "httparty" HTTParty.get "http://www.google.se" Then it woul...

Convenience methods for Ruby's Number class and 0.

I'm writing convenience methods to check if number is positive or negative like so: class Numeric def positive? self > 0 end def negative? self < 0 end end but in this case I do not know how to handle cases like these: >> 0.positive? >> 0.negative? Update: I've updated the typo in the class name. I used numeric bec...

Read from stdin or file in single stagment in ruby

I have this code if filename begin if filename == '-' ARGF.each{|url| begin check(url) rescue Timeout::Error, Errno::ETIMEDOUT puts "Timeout Error, try again" redo end } else File.open(filename) {|file| file.each{|url| begin c...

How to tell Terminal which version of Ruby to use?

Hello, I have two related questions that I was hoping someone could help out with. I recently installed Ruby 1.9.2 on my Mac (running Snow Leopard 10.6.4) and I haven’t been able to figure out how to get Terminal to use the new Ruby as a default, rather than the factory-installed Ruby 1.8.7. The old Ruby 1.8.7 is located in my ~/usr/...

How to build a Ruby extension with Objective-C using new exceptions (@throw…)?

I have build a Ruby extension in Objective-C. Now I want to use @throw/@catch etc. instead of macro based exception handling and self build error handling. I am using the GNU runtime shipped with the GCC. When I run my Ruby app with my extension it core dumps as soon as an exception occurs. The abort() comes from the GNU Objective-C r...

Fire up a web browser for a folder?

Is there an easy way to fire up a web browser for a folder? eg. I am in a folder that contains a website (index.html and other files) and I want to browse the site through a browser. Is there a gem that I just launch to make this folder browsable? In this way I don't have to install nginx just for a specific folder. And when you insta...

How to manage multiple gemsets and ruby versions with RVM ?

I am really confused by the explanations given in RVM website. The relation between different ruby interpretors and gemsets are not clear to me. According to me, it is like this - My Account in my Mac have one rvm That rvm installs and manages set of different versions of ruby interpretors. each ruby version has set of gemsets. Am ...

Using variables in regex for string search in Ruby

I'm trying to search a string for match on an array of words. I tested the code by specifying a word and also an input and it correctly finds it, but for some reason I can't get it to work in general. I checked that the input is a String and the words are extracted from the list as well. Any help on this would be appreciated. Thanks...

How to format decimals

I need to format float like price for two decimal places and thousands spaces, like this: "1 082 233.00" ...