ruby

Any chances to imitate times() Ruby method in C#?

Every time I need to do something N times inside an algorithm using C# I write this code for (int i = 0; i < N; i++) { ... } Studying Ruby I have learned about method times() which can be used with the same semantics like this N.times do ... end Code fragment in C# looks more complex and we should declare useless variable i...

Ruby networking problem on windows

I am running windows XP with ruby 1.8.6 patchlevel 111. I am using HTTP to connect to a remote server and it has been running fine. All of a sudden it started to through the exception listed below (I did not change any code since the last time I ran it successfully). Does anybody know what is going on? c:/ruby/lib/ruby/1.8/timeout.rb...

OO Design: Multiple persistance design for a ruby class

Hi all, I am designing a class for log entries of my mail server. I have parsed the log entries and created the class hierarchy. Now I need to save the in memory representation to the disk. I need to save it to multiple destinations like mysql and disk files. I am at a loss to find out the proper way to design the persistence mechanism....

What scares you the most about the integrated IDE of most modern Smalltalks?

As I'm riding the wave of resurgence of Smalltalk (especially because many Ruby-on-Rails people are rediscovering Smalltalk and seeing Seaside as their next upgraded web framework), I get questions like "yeah, but how do I use my favorite editor to edit Smalltalk code?" or "Does Smalltalk still insist on living in a world of its own?". ...

Where can I get the missing figures from the freely available, classic "Programming Ruby" e-book?

I am studying the content of "Programming Ruby- The Pragmatic Programmer's Guide" but the HTML version does not include the Figures. Are the figures available anywhere online? ...

How can I copy a mySQL Database in ruby on rails?

We are making a Ruby On Rails webapp where every customer gets their own database. The database needs to be created after they fill out a form on our website. We have a template database that has all of the tables and columns that we need to copy. How can I do this in programatically from ruby on rails? ...

What are the limits of ruby on rails?

I have a memory of talking to people who have got so far in using Ruby on Rails and then had to abandon it when they have hit limits, or found it was ultimately too rigid. I forget the details but it may have had to do with using more than one database. So what I'd like is to know is what features/requirements fall outside of Ruby on R...

JQuery selectors not finding class on elements in table created by an Ajax XHR in Ruby on Rails

When using $('.foo').click(function(){ alert("I haz class alertz!"); return false; }); in application.js, and <a href = "" class = "foo" id = "foobar_1" >Teh Foobar </a> in any div that initializes with the page, when clicking "Teh Foobar" it alerts and doesn't follow the link. However, when using the same code in a...

Ruby on Vista

I installed Ruby and Ruby on Rails yesterday on Vista 32bit using the directions on this site: http://rubyonrails.org/down so I downloaded the installer, then Gems, then I downloaded rails with Gems. now I can't use the Gem or Ruby commands in the command line... so I assume there's something wrong with the environment variables, but I...

Best way to add full web search to my site?

I need to add full web search to my site. I need something like Google Custom Search but with no ads and it has to be free. Any recommendation of a web service or open source project that can index my site and allow me to search it will be helpful. My site is made in ruby on rails, if that helps. I'll make this question community-wiki ...

How can I cache a calculated column in rails?

I have a tree of active record objects, something like: class Part < ActiveRecord::Base has_many :sub_parts, :class_name => "Part" def complicated_calculation if sub_parts.size > 0 return self.sub_parts.inject(0){ |sum, current| sum + current.complicated_calculation } else sleep(1) return rand(10000) e...

How do I get the unique elements from an array of hashes in Ruby?

I have an array of hashes, and I want the unique values out of it. Calling Array.uniq doesn't give me what I expect. a = [{:a => 1},{:a => 2}, {:a => 1}] a.uniq # => [{:a => 1}, {:a => 2}, {:a => 1}] Where I expected: [{:a => 1}, {:a => 2}] In searching around on the net, I didn't come up with a solution that I was happy with. Fo...

Ruby Memory Management

I have been using ruby for a while now and I find for bigger projects it can take up a fare amount of memory. What are ruby best practices for reducing memory usage? Please, let each answer have on "best practice" and let the community vote it up ...

Ruby on Rails - Can I modify the value of an attribute before it is called?

Let's say I have this model named Product with a field named brand. Suppose the values of brand are stored in the format *this_is_a_brand*. Can I define a method in the model (or anywhere else) that allows me to modify the value of brand before it is called. For example, if I call @product.brand, I want to get This is a Brand, instead of...

Alter :path_prefix dynamically when calling has_attachment via Attachment Fu plugin

By default Attachment Fu stores uploaded files in "public/#{table_name}". I want to modify this to be something like "public/#{table_name}/#{site_id}", where site_id is a property of the model. Note that I've tried using self.site_id and both fail. has_attachment :storage => :file_system, :max_size => 25.megabytes, ...

The dangers of using ExtJS on a big project with RoR?

We are developing a considerably big application using Ruby on Rails framework (CRM system) and are considering to rewrite it to use ExtJS so that Rails would just do the data handling, while ExtJS would do all the browser heavylifting in a desktop-like manner. Anyone has some experience and hints about what would be the best approach?...

Testing rails partial views standalone

Hi, I'm using Test/Unit with a standard rails 2.1 project. I would like to be able to test Partial Views in isolation from any particular controller / action. It seemed as though ZenTest's Test::Rails::ViewTestCase would help, but I couldn't get it working, similarly with view_test http://www.continuousthinking.com/tags/view_test Mos...

Current Cursor Position when Using the Prawn Ruby Library

I'm using the Prawn Ruby library (http://prawn.majesticseacreature.com/) to generate some pdf documents. I draw a table without any problem. Next, I want to insert some lines after the table for various people's signatures. Before I draw the lines, I would like to see if there is enough remaining room on the page to fit all the signat...

Ruby rufus scheduler gem

We're thinking about using the rufus-scheduler gem on a Ruby on Rails project to do regular monitoring of a communication queue. Has anyone have experience using this gem on a Rails project? Anyone have strong preferences of an alternative scheduler? ...

Monitoring Windows directory size

I'm looking for something that will monitor Windows directories for size and file count over time. I'm talking about a handful of servers and a few thousand folders (millions of files). Requirements: Notification on X increase in size over Y time Notification on X increase in file count over Y time Historical graphing (or at least sav...