ruby

How to test whether a Ruby object is immutable?

Is there an easy way to test whether an object is a immutable (numbers, nil) or not (Array, Hash, objects)? In other words, could it be changed by side effects from other code? Motivation: I want to create a versioned value store, but some of the data is arrays. Some of the arrays will store custom objects, and I could invert the rela...

How much should I charge for Rails programming?

I have been asked to quote an hourly rate for freelance programming for a Rails project. Although it would be my first paid project on Rails, I know the technology well from personal projects and have a decade of professional programming experience. This would be my first freelance project ever, so I have no idea how to find out what the...

Show full path name of the ruby file when it get loaded

When reading source code, I always want to know the full path of the file when it is loaded, is there any callback method in ruby to accomplish this, or any other way to do this? thanks in advance. EDIT Clarification from the comments: I want to know where the loaded "somefile" is located while I execute this line: "load somefile" ...

What is the best rails example app?

What is the best available non-trivial example app for rails with uptodate source, test suite and adherence to best practices? [I am looking for an example of a full fledged application - with complex data models and advanced views that is worth looking at to see "how it is done" by others] ...

Source code problem of ZenTest

Here is one method that monkey patched the Dir[] method from autotest class Dir class << self alias :old_index :[] def [](*args) $-w, old_warn = false, $-w old_index(*args) ensure $-w = old_warn end end end Could you please help by explain this line $-w, old_warn = false, $-w ? Thanks in advance. ...

Is there a way to validate a specific attribute on an ActiveRecord without instantiating an object first?

For example, if I have a user model and I need to validate login only (which can happen when validating a form via ajax), it would be great if I use the same model validations defined in the User model without actually instantiating a User instance. So in the controller I'd be able to write code like User.valid_attribute?(:login, "logi...

Is there a 'standard' read/write lock implementation for ruby?

Does anyone know of an existing ruby implementation of a read/write lock - http://en.wikipedia.org/wiki/Readers-writer_lock? Preferably this would be in a popular library or some other implementation that's been used by enough people that it's fairly bulletproof at this point. ...

What is the difference betwen including modules and embedding modules?

module Superpower # instance method def turn_invisible ... end # module method def Superpower.turn_into_toad ... end module Fly def flap_wings ... end end end Class Superman include Superpower ... def run_away # how to call flap_wings? # how to call tur...

invalid gem format

Installing Merb on Ruby Enterprise Edition (OS X) throws this error, any ideas? sudo gem install merb ERROR: Error installing merb: invalid gem format for /opt/ruby-enterprise-1.8.6-20090113/lib/ruby/gems/1.8/cache/ParseTree-3.0.2.gem Deleted the gem cache but the problem persisted. It seemed to manage to install some of the gems th...

Regex for parsing tags from a string.. Flickr style

I wonder if anyone can provide me with the regular expressions needed to parse a string like: 'foo bar "multiple word tag"' into an array of tags like: ["foo","bar","multiple word tag"] Thanks ...

Declarative ruby programming replacement for if/then/else/RETURN/end?

I have this showing up all over in my controllers: if not session[:admin] flash[:notice] = "You don't have the rights to do #{:action}." redirect_to :action=>:index return end And its sibling: if not session[:user] and not session[:admin] flash[:notice] = "You don't have the rights to do #{:action}." redirect_to :action=>:i...

What graphing packages/APIs exist for Ruby?

Similar: What graphing packages/APIs exist for Perl? I'm doing some research into online graphing packages for different languages and would like to know what current, up-to-date graphing packages there are for Ruby which are worth investigating. Minimum desired capabilities should include the kind which Google offers through its API. ...

Does Ruby support var references like PHP?

In PHP, you can make two variables point to the same data. $a = 'foo'; $b = 'bar'; $a =& $b; echo $a // Outputs: bar echo $b // Outputs: bar What we are trying to do in Ruby is set @app_session to be equal to session[@current_app[:uid]]. So we only have to deal with @app_session in our app, and everything is automatically saved to th...

How can I modify/extend a rake file from another rake file?

I'm trying to find a way to modify/extend a RakeFile from another RakeFile without actually changing it. When I run my rake task I retrieve a solution from SVN which contains a rakefile. I want to: Change a variable in this rakefile. Add a new task to this rakefile which makes use of existing tasks. Execute the new task. I want t...

Multiple submit buttons/forms in Rails

I am trying to write a rails application which lets you go to a certain page, say /person/:id. On this page it shows a set of available resources. I want each resource to have a button next to it, which reserves that resource to that person (by creating a new instance of an Allocation model.) As an extension, I'd like several buttons by ...

Regular Expression to escape HTML ampersands while respecting CDATA

I've written a content management system that uses a server-side regular expression to escape ampersands in the page response just prior to it being sent to the client's browser. The regular expression is mindful of ampersands that have already been escaped or are part of an HTML entity. For example, the following: a amp; d, &copy; 20...

Inserting DATETIME with ActiveRecord and MySQL

I am having a problem with ActiveRecord inserting the DATETIME as per the documentation; "Active Record automatically timestamps create and update operations if the table has fields named created_at/created_on or updated_at/updated_on." I have a column named created_at but ActiveRecord is not inserting the DATETIME. My insert query looks...

What's the best forum resource for Ruby on Rails?

In the past I've used RailsForum.com as a resource, but lately I've come across far too much spam and not enough useful posting. Certainly just my perspective. So, what do you Rails developers use as a forum resource for the platform? ...

Parallel processing from a command queue on Linux (bash, python, ruby... whatever)

I have a list/queue of 200 commands that I need to run in a shell on a Linux server. I only want to have a maximum of 10 processes running (from the queue) at once. Some processes will take a few seconds to complete, other processes will take much longer. When a process finishes I want the next command to be "popped" from the queue a...

How do I take the output of one program and use it as the input of another?

I've looked at this and it wasn't much help. I have a Ruby program that puts a question to the cmd line and I would like to write a Python program that can return an answer. Does anyone know of any links or in general how I might go about doing this? Thanks for your help. EDIT Thanks to the guys that mentioned piping. I haven't use...