Category Archive: ruby

Apr 22

The Cost of Using Ruby’s Rescue as Logic

Rescue Logic is Expensive

  Code like this: unless nodes.nil? nodes.first else return end Can be written using the seemingly more elegant approach with this ruby trick: node = nodes.first rescue return But then, that got me to thinking… In many languages I have used in the past (e.g., Java and C++), Exception handling is an expensive endeavor. So, …

Continue reading »

Apr 24

MongoMapper Query Overview

There was a question on the MongoMapper Google Group from a Mongoid user about how MongoMapper handles associations. Brandon was surprised that this query returned an Array: Product.first.releases.where(something) Let’s break it down, one bit at a time and clear things up: # This would be an instance of Product Product.first # Class. This simply gets …

Continue reading »

Apr 22

Looking at Gem Code is Easy with GemEdit

Mongo Mapper

Ever want to pop into the source code of some gem that you are using? Gem Edit is a nice and easy way to do this (if you aren’t using RubyMine, for example): [sudo] gem install gemedit In the terminal, simply type: [develop*]$ jonsmac2-2:source jon$ gem edit -e mate mongo_mapper And you will see: Found …

Continue reading »

Apr 20

Factory Girl and MongoMapper

Factory Folder

You were probably hoping for some Rosey the Riveter poster… Instead, I am going to extend my small MongoMapper example to include Factory Girl. The steps are pretty simple: Go here to install… Create your factories Use the factories in Cucumber/RSpec Factory Construction I created a new “factories” folder under the spec folder: The factories …

Continue reading »

Apr 18

Pow — A Great Server for your Mac Bat Cave

Symbolic Link to Rails3 App

Somehow I stumbled across this great little tool  — oh yeah, John Nunemaker mentioned “powder,” which was “Syntactic sugar for http://pow.cx/” Huh? Syntactic what? For “pow” what? John hasn’t steered me wrong yet, so I decided I needed to look at what Pow was. In 37Signals own words: Pow: Zero-configuration Rack Server for Mac OS …

Continue reading »

Apr 17

RVM Install Troubleshooting

All I wanted to do was sit down with Mike Hartl’s “Ruby on Rails 3 Tutorial” yesterday. Hours later, with nothing to show other than a zillion open terminals, I punted and watched the Flyers beat the Sabres despite playing like girls (I know, unfair to girls!). Then I went to bed. So I must …

Continue reading »

Apr 12

Ruby Metaprogramming in the Small

I have been thoroughly enjoying working with Ruby this past year (thanks Lee!). However, only recently have I been getting brave/comfortable/wise enough to try out some metaprogramming. Okay, so maybe I am a little slow… The scourge of making deadlines and releasing software meant I sometimes just had to give up trying to get to …

Continue reading »

Mar 27

MongoMapper vs MongoDB Cursor Stats

Compare Processing Speed and Memory Usage for Cursor and Array Approach

I just love developing with MongoMapper and MongoDB… This weekend I had an easy opportunity to test out the performance between iterating through a collection via MongoMapper or MongoDB cursor. (I had to fix up a field that I munged by screwing up some production code — oops) My findings showed that the cursor approach …

Continue reading »

Feb 09

Don’t Fight Ruby!

In this blog post, “Adding Type Checking to Ruby,” I spit up a little bit in my mouth. I don’t want to be harsh… I can appreciate Daniel’s different approach to Ruby. Mind you, I’m no Ruby whiz (yet), but look at this example: def create_name(fname, lname) raise “fname must be a String” unless fname.kind_of? …

Continue reading »