Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 RUBY


  Never create Ruby strings longer than 23 characters

Looking at things through a microscopesometimes leads to surprising discoveriesObviously this is an utterly preposterous statement: it’s hard to think of a more ridiculous and esoteric coding requirement. I can just imagine all sorts of amusing conversations with designers and business sponsors: “No… the size of this <input> field should be 23… 24 is just too long!” Or: “We need to explain to users that their subject lines should be less than 23 letters…” Or: “Twitter got it all wrong… the 140 limit should have been 23!â€...

2,434 0       RUBY OPTIMIZATION SPECIFICATION STRING INTERPRETER 23


  I don’t like the Ruby 1.9 hash syntax

There, I said it, I don’t like it. And I don’t know why you do either.I assume you like it anyway, everyone else I talk to seems to. My heart sank over and over again whilst I was at the recent RailsConf and saw respected rubyist after respected rubyist using the new Ruby 1.9 hash syntax in their presentations.I just don’t get it.But I’m not one to just moan. I plan to justify my feelings. Then maybe you can tell me why you do like it?My friend the hash rocketI like the hash rocket (not least because it’s a rocket) and I know it’s not going away. Howev...

7,773 0       RUBY FEATURE 1.9 HASH


  Learning Ruby and Ruby vs Lisp

The company I work for has a lot of legacy Ruby code, and as Ruby has become kind of a mainstream language, I decided to get a book about it and learn how it works. As my learning resource, I chose The Ruby Programming language by David Flanagan and Yukihiro Matsumoto as that receives great customer reviews, covers Ruby 1.8.7 and 1.9 and is authoritative because the language creator is one of the authors. The book makes a good read in general. There are plenty of code examples, but not too much to obscure the prose. What I found first interesting, later annoyi...

6,475 1       OOP RUBY DIFFERENCE FEATURE FUNCTIONAL LISP


  Method chaining and lazy evaluation in Ruby

Method chaining has been all the rage lately and every database wrapper or aything else that’s uses queries seems to be doing it. But, how does it work? To figure that out, we’ll write a library that can chain method calls to build up a MongoDB query in this article. Let’s get started!Oh, and don’t worry if you haven’t used MongoDB before, I’m just using it as an example to query on. If you’re using this guide to build a querying library for something else, the MongoDB part should be easy to swap out.Let’s say we’re working with a...

3,095 0       RUBY IMPLEMENTATION METHOD CHAINING LAZY EVALUATION


  Don't Overload #nil?

There’s a popular post on Hacker News about writing confident code by, among other things, overloading Object#nil? and returning “null objects” instead of nil itself.DO NOT DO THIS.In Ruby, all objects (except nil itself) coerce to the boolean value true. Your object will be nil and true at the same time. Bad things will happen. Your coworkers will cry. Sad people from around the world will ask bewildering questions on your mailing list.Here’s what happens:1234567891011class NullObject def nil? true endendo = NullObject.newo.nil? #=>...

2,793 0       RUBY OBJECT #NIL OVERLOAD