ruby

How to update ruby on linux (ubuntu)?

I'm newbie on both ruby and linux, so I'm sure this is trivial but I don't know yet. I currently have ruby 1.8.7 installed and I want to update it to ruby 1.9. How can I do that? Thanks in advanced. ...

256 color terminal library for Ruby?

Is there a gem like 'Term::ANSIColor' which works with 256 color terminals? The perl script 256colors2.pl works great in my terminal, and I'd like to use some of these colors in my ruby scripts without manually inserting the ANSI codes. ...

Why can't Cygwin CVS read the CVS password file in a Ruby/Perl script?

On the Windows command line and cygwin bash I can execute the following without problems: cvs login cvs -Q log -N -rVersion_01_00 A ruby script in the same directory contains the following: `cvs login`; `cvs -Q log -N -rVersion_01_00`; When I execute the ruby script on the Windows command line I get the following error: cvs log: w...

RDoc XML generation

I'm trying to generate a RDoc using the XML format. Here's the command that I'm using: $ rdoc --fmt=xml --opname=api.xml The file is created but no method list is generated. I'm using rdoc (2.4.3). The RDoc template for XML include tags for method displaying. Is it possible? ...

Do I need to parenthesise yield in Ruby?

In Ruby I can use result << (yield element) and everything works, but if I do result.push(yield element) I get a warning about needing parentheses for future compatibility. I can change the above to result.push(yield(element)) and the interpreter is happy again, but I don't understand why I need parentheses in one call to yield ...

Is there something like Ruby's Machinist for Python

Copied from the site http://github.com/notahat/machinist/ Machinist makes it easy to create test data within your tests. It generates data for the fields you don't care about, and constructs any necessary associated objects, leaving you to only specify the fields you do care about in your tests A simple blueprint might look like...

Using Rails Migration on different database than standard "production" or "development"

Hi! I have a rails project running that defines the standard production:, :development and :test DB-connections in config/database.yml In addition I have a quiz_development: and quiz_production: definition pointing to a differnet host/db/user/password My goal now is to define a Migration that uses "quiz_#{RAILS_ENV}`" as its database ...

one line ruby array creation and population...

This is fairly trivial, but it bothers me to no end that I haven't yet found the answer using Google or this forum. But how can i turn this into one line? Without have to declare rooms an array above? rooms = [] hwdata.availability.each {|room| rooms << room.name} ...

Rails: do we have anything built-in to output a ruby array as arguments to a javascript function call?

Hi, Here's what I want, in wishful code: in my controller action: @javascript_function_args = [ "foo", "bar", 1, [2, 3], { :zort => 'narf', :nom => 'cake' }] in my erb view: <script … > performAwesome(<%= @javascript_function_args.to_js_args %>); </script> or, even better: <%= call_javascript_function :performAwesome, *@java...

retrieving page title in rails

Curious as to how to approach this same problem using ruby / rails - http://stackoverflow.com/questions/399332/fastest-way-to-retrieve-a-title-in-php Is there a plugin or gem that anyone recommends? cheers! ...

COM types question

I have this vendor-supplied TLB file, which I've used to generate a Ruby proxy class. However, the TLB in question describes 6 interfaces and 3 classes: AcdAutomationServer (I) AcdAutomationServerClass (C) AcdEvent (I) AcdEventClass (C) AcdObject (I) AcdObjectClass (C) IAcdAutomationServer (I) IA...

Reorganizing Ruby array into hash

I have an array of Products, each of which has a name and a category. I would like to produce a hash in which each key is a category string and each element is a product with that category, akin to the following: { "Apple" => [ <Golden Delicious>, <Granny Smith> ], ... "Banana" => ... Is this possible? ...

How to access to ghost parent classes in ruby?

Hi, I was watching the first ruby metaprogramming screencast by prag dave. At some point he said that ruby introduce 'ghost classes' when you add a method to an instance variable. i. animal = "cat" def animal.speak puts "hola" end animal.speak # => hola animal.class # => String dog = "dog" dog.speak # Undefined ...

Should the Applicant class "require 'mad_skills'" or "include 'mad_skills'"?

Also, what does "self.send attr" do? Is attr assumed to be a private instance variable of the ActiveEngineer class? Are there any other issues with this code in terms of Ruby logic? class Applicant < ActiveEngineer require 'ruby' require 'mad_skills' require 'oo_design' require 'mysql' validates :bachelors_degree def qual...

rails time demon in my machine... it eats 2 hours have checked everything!

I have my checked my environment.rb config.time_zone = 'Prague' Nothing in development.rb regarding time This seems to work, in theory... Time.zone.now # Thu, 10 Sep 2009 17:51:35 CEST +02:00 also correct... Time.now # Thu Sep 10 17:52:10 +0200 2009 mysql... SELECT NOW() # 2009-09-10 17:53:48 correct! but when I create a new ...

Why does with_progress do "Thread.new"?

This code installs gems into your project based on a gem manifest. Why does it need to spawn threads for this? module Gemifest class Installer def initialize(gem) @gem = gem end def perform! begin $stdout = StringIO.new('') $stderr = StringIO.new('') with_progress 'Installing ' + @gem.n...

Problem creating ActiveRecord model: data missing from save

Hi all, I'm having trouble creating a new model row in the database using ActiveRecord in a Sinatra app I'm developing. The object in question is being created without any errors (using save!, no exceptions are raised), but most of the data I specify for the save is not present. class ProjectMeta < ActiveRecord::Base attr_accessor ...

how to calculate next, previous business day in rails

how to calculate next, previous business day in rails. ...

What is the purpose of `@ins << lambda` in this code?

In the first method listed below, the use method, it looks to me like :ins is an instance variable and attr is a method that provides getters and setters for :ins. What I'm not sure is what the @ins << lambda does. module Rack class Builder attr :ins def use(middleware, *args, &block) middleware.instance_variable_set "@r...

what are the advantages of mocha over rspec's built in mocking framework?

I notice that a lot of people prefer mocha over rspec's built in mocking framework. Can someone explain the advantages of mocha, or any alternative, over rspec's built in mocking framework? ...