Quantcast
Channel: iain.nl
Browsing all 133 articles
Browse latest View live
↧

Basic Named Scopes

Cal it tiny, I don't care. I've made a gem named BasicNamedScopes. Basic Usage I was fed up with writing: Post.all(:conditions => { :published => true }, :select => :title, :include =>...

View Article


http_accept_language released as a gem

I released an old Rails plugin as gem today. Slowly but surely, all my plugins will be converted to gems. This time it's an old one: http_accept_language Splits the http-header into languages specified...

View Article


3 times ActiveSupport 3

Rails 3 is coming. All the big changes are spoken of elsewhere, so I'm going to mention some small changes. Here are 3 random new methods added to ActiveSupport: presence First up is Object#presence...

View Article

Going crazy with to_proc

You all know Symbol#to_proc, right? It allows you to write this: # Without Symbol#to_proc [1, 2, 3].map { |it| it.to_s } [3, 4, 5].inject { |memo, it| memo * it } # With Symbol#to_proc [1, 2,...

View Article

Monkey Patch of the Month: group_by

A while back, I talked about new additions to ActiveSupport. And now, I have a confession to make: I like monkey patches! At least, as long as they're short and self-explanatory. I got a few of them...

View Article


Odd Ruby Methods

I recently encountered some methods I didn't know about. ~ The tilde method (~) is used by Sequel and you can use it like this: class Post def ~ 11 end end post = Post.new ~post # => 11 That's...

View Article

Monkey Patch of the Month: attr_initializer

So, about one month ago, I promised to share some useful monkey patches every month. Here is the second one. Your own monkey patches are still more than welcome! I often find myself writing code like...

View Article

Qu'est-ce que c'est Rubyesque?

This is a translation of the post I originally wrote down in Dutch for my company. I recently gave a presentation at my company Finalist IT Group about the philosophy behind Ruby. Code written with...

View Article


ViewTranslator, a dynamic dispatcher

I'm a sucker for syntax. So once again, here's a small experiment. It might not be the most useful snippet out there, but maybe it inspires you to do something awesome. The 'Dynamic Dispatcher' is a...

View Article


Image may be NSFW.
Clik here to view.

Conway's Game of Life; or: Writing Perl in Ruby

We had a programming exercise this week at work. We were set out to write Conway's Game of Life, using pair programming and TDD. It was a fun and educational evening. I even did some Scala. Programmers...

View Article

Helpers Are Code Too!

I think I've talked about this before, and there has been a Railscasts episode about it too, but I want to touch on it again. I know we're supposed to keep views simple, but that doesn't mean that...

View Article

Cheating Performance With A Little Javascript

This little trick works with most websites with a menubar. When you have a menu that changes color pending on which page you are, you can cheat a bit on the perceived performance of loading pages. And...

View Article

About structs

Recently I talked about a monkey patch called attr_initializer, allowing you to write code like this: class FooBar attr_initializer :foo, :bar def to_s "your #{foo} is #{bar}" end end FooBar.new('foo',...

View Article


Using Sass with jQuery UI

Want to build a quick website or backend? Want to make it look good, but without adding too much effort in it? Then this recipe is for you! The jQuery UI framework contains some nice styles and some...

View Article

Image may be NSFW.
Clik here to view.

Customizing IRB, 2010 edition

TL;DR: Check out my new .irbrc-file! Customizing my work environment is a nerdish hobby of mine. I spend far to much time tweaking my terminal. While I'll save my terminal customizations for another...

View Article


Domain Driven Design: Building Blocks in Ruby

A few weeks ago I talked about Domain Driven Design in Ruby at the local Ruby user group: Rotterdam.rb. It had a great turnup (even though the weather prevented some from coming) and there was a good...

View Article

Building Blocks of DDD: Services

As promised, here is an example of how to use the idea of services from Domain Driven Design to help you design your code better. Let's start with some theoretical stuff, before we dive into some...

View Article


Gemfile vim syntax file

I've updated my Gemfile syntax file, adding a dash of color and making sure it supports all elements of the Bundler DSL. You can get it here. You'll also need to tell vim to automatically use it when...

View Article

Your argument doesn't cut wood

About once a month I read an article on comparing Ruby to another programming language. Usually it makes the point that Ruby is dynamic and open and therefore it is less suited for reliable...

View Article

Image may be NSFW.
Clik here to view.

RSpec Array Matcher

If you're testing arrays a lot, like ActiveRecord's (named) scopes, you should know the following RSpec matcher: =~. It doesn't care about sorting and it gives you all the output you need when the spec...

View Article
Browsing all 133 articles
Browse latest View live