Ruby Objects and Dot Syntax

Coming from JavaScript I’m very accustomed to doing something like this:

Javascript
var person = { name: 'Rob', city: 'San Francisco' }

console.log( person.city );   // 'San Francisco'

Using dot syntax to access a Hash is second nature to me. That’s why I was surprised when I ran into the following error yesterday while writing some Ruby.

Ruby
person = {name: 'Rob', city: 'San Francisco'}
 => {:name=>"Rob", :city=>"San Francisco"}

puts person.city

NoMethodError: undefined method `city' for {:name=>"Rob", :city=>"San Francisco"}:Hash

“Hmm, weird,” I thought. I know I’ve seen dot syntax used in Ruby before..what gives?

Custom Domain With Octopress and Github Pages

I’m going to try to write this as a bit of a lightening post to see if I can bring down the time it takes me to produce something.

Octopress is a blogging framework written by Brandon Mathis (@imathis) which sits on top of Jekyll. Jekyll is a static site generator, meaning there’s no database associated with your blog. Instead of writing everything in a WSYWIG linked to MySQL (like Wordpress or Blogger) you produce text files using Markdown which are then converted to static HTML. There are 3 huge benefits to this approach. First, writing in Markdown is awesome. Once you learn the syntax it’s incredibly fast and you don’t have to spend time playing with a tiny little editor window just to add some style to your posts. Second, writing in your favorite text editor is also awesome. I produce everything in Sublime Text 2 and every day I discover new tricks to make the process better. If you’ve ever had to write a blog post using one of those horrible little TinyMCE editors you will appreciate this feature. And lastly, static HTML is fast.

Playing With Ruby Dates

One of my previous projects involved a ton of work using Flash’s built in Date object. We ended up rolling our own Calendar library which was both tedious and time consuming to debug. Now that I’m digging into Ruby for my newest project, I wanted to see what features the language has to offer. So far I’m really impressed and that’s after only a few hours of exploration. I’ll detail some of the tricks I’ve learned along the way so hopefully other newcomers can benefit.

How to Setup PostgreSQL for Rails and Heroku

Install PostgreSQL Locally

Ryan Bates has already put together a wonderful Railscast on this topic so feel free to jump over there to view it. My main goal in writing this post was to distill down what he said, point out a small gotcha along the way and offer some additional tools.

A Basic RVM Tutorial for Rails 3

What is RVM?

RVM is a great Ruby and gem management tool that should probably be the first thing you install if you’re learning Rails (or Ruby for that matter). The main benefit of RVM is that it helps to keep your rubies and your gems organized into discrete folders which can easily be thrown away and recreated. If you’ve ever had a gem explode on you, then you know how great a feature like this is. I’ll cover the basics of using RVM in this post to quickly get you up and running. This tutorial is written for the OSX terminal, if you’re on Windows…um…kill yourself.

Syntax Error: Unexpected tIDENTIFIER in Rails 3

Today we’re going to look at this little gem, which is really nothing more than a syntax error. If you’re not used to Ruby’s syntax, this can be a particularly easy stumbling block.