Posts about Ruby

String Difference in Ruby

class String def -(other) self.index(other) == 0 ? self[other.size..self.size] : nil end endThis snippet gives the Ruby String class a minus operator. Which works like> 'abcde' - 'abc'=>... more
Posted by Toby on Mar 25, 11
About programming and ruby

HTTP Server in 5 Lines With Webrick

Usually when I am prototyping a web UI - either in Javascript or Flex, I would just write a static html, because that's the simplest thing that works. But, once in a while, it doesn't work because of... more
Posted by Toby on Sep 16, 09
About programming, javascript, ruby and html
2 comments

The New-Found-Love for Dynamic Languages

Posted by Toby on Aug 04, 09
About programming, ruby and haskell

Null in 10 Languages

  • Java, Javascript, C#: null
  • Ruby, Smalltalk, Lisp, OCaml: nil
  • Lisp: ()
  • Python: None
  • Haskell: Nothing
  • C: 0
more
Posted by Toby on May 11, 09
About programming, javascript, ruby, smalltalk, haskell, ocaml, python, java, c#, lisp and c

ActiveRecord Gotcha

I came across this interesting gotcha while debugging through someone else's rails code. When you set a model's one-to-many attribute(an perhaps other association types as well), let's... more
Posted by Toby on May 01, 09
About programming, ruby, rails and gotcha

Auto-mixin in Python

Python has multiple inheritence - a feature that's really handy because it allows the programing idiom called mixins - where you write a a bunch of methods on a "mixin" class and then later on... more
Posted by Toby on Jan 18, 09
About programming, ruby, metaprogramming, python and mixin

Ruby Gotcha of the Day

Okay, so in ruby:>> nil or 'value'=> "value"because nil acts as false when used with boolean operators and any other object acts as true. Now let's assign the result to a temp variable a:>> a =... more
Posted by Toby on Dec 26, 08
About programming, ruby and gotcha

Impressions of Turbogears 4 months in

I've been a user of Turbogears for 4 months now, working on a client facing app. The app has not gone production yet, so I don't have much insight on deployment, but I have a lot of experience on the... more
Posted by Toby on Jul 17, 08
About programming, ruby, python and turbogears

Getting the Argument Names of Your Function

In Javascript:myfunction.toString()This gives you the entire definition of the function as a string, with which you can parse to get the argument names, or in prototype.js you can just... more
Posted by 宝宝妈, Toby on May 20, 08
About programming, javascript, ruby and python

How Safe is Your Programming Language

First, let me define what I mean by safe: the earlier a programming language catches a programming error for you, the safer it is. Haskell is extremely safe, whereas php is extremely unsafe. Some... more
Posted by Toby on Mar 30, 08
About programming, javascript, ruby, smalltalk, haskell, ocaml, python, java, c#, lisp and c
2 comments

Ruby: Extremely Unsafe

I have been making the same mistake a few times recently: instead of writingthings.each do |thing| ... endWhere things is a method, not a variable, I would write:things do |thing| ... endwhich has... more
Posted by Toby on Mar 15, 08
About programming and ruby

Autotest popup notifications with Snarl

After learning of growl from Micah's post, I decided to port it to the windows equivalent: snarl. It was pretty easy:Follow Micah's instructions except for the growl bitsInstall Snarl from their... more
Posted by Toby on Mar 14, 08
About programming, ruby and testing