ruby

Python/Ruby as mobile OS

I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language. What would be the reasoning behind a mobile OS being written in Python, Ruby, or any other dynamic language? I unders...

How do you figure out what the older versions are for a particular Ruby Gem?

How do you figure out what the older versions are for a particular Ruby Gem? I need to revert to an older version of the rack gem but I'm not sure which versions are available. ...

Are there any potential disadvantages in using a Ruby framework other than Rails?

I would like to use a lighter framework than Rails (Sinatra/Ramaze/Camping) but am concerned that by doing so I will not be able to use a lot of shared libraries that have been tailored to Rails in the form of plugins. Is this a major concern or are most of these plugins usable across different Ruby frameworks? Are there any other poten...

Multiple references in Ruby

I expected the following code to print "8", "111" and "999". I supposed that each a, b, c and d points to the same memory location. If I change the location through one of them, why would the other not to change? Clearly, my logic is poor, or I overlooked something. It prints "7", "7" and "8", instead. Why? a=b=c=d=7 b = 8 ...

AR.to_json Works in Console, Fails in Browser

I have this block of code: users = Array.new users << User.find(:all, :conditions => ["email like ?", "%foo%"]) users << User.find(:all, :conditions => ["name like ?", "%bar%"]) users.flatten! users.uniq! puts users.to_json :include => [:licenses] When I run it using script/console, it returns exactly what you would think it should, a...

Rails - Constants Hash?

I have a need for a model(?) on my app which basically contains a status of another entity. In the entity I want to store the id of the status, but in my app, the view is talking in terms of a nice word description. For instance, 1=New, 2=Used etc etc. How can I go about implementing this in the best way that means I can easily set an...

Problems with nested form fields showing up

Hi, I'm attempting to implement nested object forms for my site, using Ryan Daigle's blog post as a guide (http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes). For some reason, the nested form fields don't appear in the view. class Instruction < ActiveRecord::Base has_many :steps accepts_nested_attri...

Is there an equivalent of isitruby19 for rubinius?

Is there a web site that indicates which gems work on rubinius (or other implementations of ruby), like isitruby19.com indicates which gems work on ruby 1.9? (I'm curious about heckle working with rubinius in particular) ...

Get person's age in ruby

I'd to get a person's age from it's birthday. now - birthday / 365 doesnt work, because some year has 366 days. I came up with following code: now = Date.today year = now.year - birth_date.year if (date+year.year) > now year = year - 1 end Is there a more rubyish way to calculate age? ...

Directory dependencies with rake

I'm using rake to copy a directory as so: file copied_directory => original_directory do #copy directory end This works fine, except when something inside of original_directory changes. The problem is that the mod date doesn't change on the enclosing directory, so rake doesn't know to copy the directory again. Is there any way to hand...

How to split single quoted comma delimited values containing commas in Ruby

Say I have a string with comma delimited values enclosed in single quotes that may or may not include commas, like this: "'apples,bananas','lemons'" and I want to split that into an array ["apples,bananas", "lemons"] Apparently, if I split(',') the string I get [ "'apples", "bananas'", "lemons" ] which I don't understand. The o...

How to run my ruby application using ruby extension library (in c), in windows?

Hello, I would be thankful for any help on this: I want to write an extension to my c library. I created file zmq.cpp that uses library libzmq (written in C++). I created makefile using ruby extconf.rb, then I run nmake. It all went fine. Nmake generated files librbzmq-i386-mswin32.def librbzmq-i386-mswin32.lib librbzmq-i386-mswin32...

Has_many class name not working like I thought?

I have a user and post model: class User < ActiveRecord::Base has_many :sent_posts, :class_name => 'Post' end class Post < ActiveRecord::Base belongs_to :user end The problem is that in the console, if I do User.first.sent_posts.empty? it returns True. But if I do this in my view <%= @user.sent_posts.empty? %> it returns F...

Nokogiri: Select content between element A and B

What's the smartest way to have Nokogiri select all content between the start and the stop element (including start-/stop-element)? Check example code below to understand what I'm looking for: require 'rubygems' require 'nokogiri' value = Nokogiri::HTML.parse(<<-HTML_END) "<html> <body> <p id='para-1'>A</p> <div clas...

Ruby & Rules Engines

Hi there, I'm looking for a simple way to let users define a set of rules to filter objects. Eg. let them define something like "notify me about a booking if booking date < 2009/04/30 AND value > 100.00" More or less: I'd like to have a Ruby rules engine with custom DSL. Is there a library offering that? Came across Ruleby, but it do...

Is there a SOAP::Lite equivalent library in ruby?

I want to build a SOAP client using ruby. I tried using the soap4r library to generate ruby classes out of the WSDL file, but the issue with this was that all the methods it generated were of optional kind, instead of NAME/VALUE pairs. Given that some methods have a very large number of arguments, many of which are optional, I would pref...

Should I use .erb or .rhtml files for a Rails app in which all Controller logic exists in Views?

I'm just starting to learn Rails. I created an empty Rails app. And instead of writing a Controller, I want to put all of my Controller logic in my Views instead of in separate Controller classes. To do this, should I use .erb files or .rhtml files and what's the difference? ...

How does Phusion Passenger reuse threads and processes?

I am setting up an Apache2 webserver running multiple Ruby on Rails web applications with Phusion Passenger. I know that Passenger spawns Ruby processes for handling requests. I have the following questions: If more than one request has to be handled at the same time, will Passenger spawn multiple processes or multiple (Ruby) threads? ...

Generating fields containing newline with Ruby CSV::Writer

I want to make CSV::Writer generate a line break within a quoted string: A,B,"Line Line",C So that the row would display in Excel as: A,B,Line,C Line Is it possible to prevent CSV:Writer from stripping out newlines? If not, would switching to FasterCSV solve this problem? ...

What are the "Must Have" Ruby Gems

I am relatively new to ruby, and I've been amazed with some of the Gems available. Sinatra comes to mind (one of the simplest ways to create working RESTful interfaces I've ever seen). So I was wondering, what are some of the coolest or most amazing Gems my fellow programmers have found, that a newbie Ruby guy should look at. Im not l...