The If Works This dirt was a building before

Metaprogramming

Announcing Heist, a new Scheme implementation written in Ruby

There seems to be a tradition of some two years’ standing that dictates I must release some piece of open source software on or around my birthday. A couple of years ago it was Flagger, a Rails plugin for doing useful things with boolean ‘flag’ columns in your database, and last year it was (with [...]

And now, the rules

In my last post I wrote about how to write your own mini-language in Ruby by abusing method_missing and operator overloading. I know, I know, it totally blew your mind and whatever, but I missed out this huge part of the language I was demonstrating: the rules. And without the rules, all it’s good for [...]

Writing your own expression language in Ruby

The last few days, I’ve been writing Consent, a tool for writing declarative firewalls for Rails apps. I thought it would be interesting to dig into its implementation now that the code’s settled down, as it’s one of the more complicated DSLs I’ve written, and certainly the first one that makes decent use of Ruby’s [...]

Consent: a little firewall DSL for your Rails app

Well, it’s been a couple of months. Rest assured I’ve still been hacking away; JS.Class will be getting hashes and constants at some point in the future, I’ve got a bunch of improvements to make on Bluff, and I’ve been contributing to PDoc which is a really promising JavaScript doc engine from Tobie Langel that [...]

New possibilities with modules in JS.Class 2.0

It’s been out and about a couple months now, and I’ve been putting it to good use in the upcoming release of Ojay. The new version (fingers crossed it’ll be out by the end of the month) features an extension to the custom event system that lets events published using Observable ‘bubble’ up the type [...]

Inheritance, revisited

Late last year, I wrote a piece titled “Where’s my inheritance“, in which I argued against the inheritance implementation of various JavaScript libraries. I’ve recently been working on a rewrite of JS.Class that is much more Ruby-like, and it’s caused me to re-examine my thoughts on this issue. With JS.Class 1.x, I made the conscious [...]

A plea to IE

Please, please implement getters and setters in your JavaScript engine. I cannot tell you how much I want to add this to JS.Class: var MagicMethods = { included: function(klass) { var define = function(object, name) { var shortName = name.replace(/^[gs]et[A-Z]/, function(s) { return s.charAt(3).toLowerCase() }); if (/^get[A-Z]/.test(name)) object.__defineGetter__(shortName, function() { return this[name]() }); if (/^set[A-Z]/.test(name)) [...]

JS.Class 1.6.0: Forwardable, State, and Ruby

A little update: JS.Class 1.6.0 is now out. The main new features are a port of Ruby’s Forwardable module for method delegation, an implementation of the State pattern (which I’m using heavily for building UI code), and JS.Ruby, which is something I wrote about a few weeks back. Also, I’ve implemented the extended hook to [...]

Quick and dirty icons in ActionView

Tiny tiny Rails tip: you can use method_missing to make using icon sets easier when writing Rails views. Behold: module ApplicationHelper def method_missing(sym, *args) super unless sym.to_s =~ /_icon$/ image_tag(“silk/#{sym.to_s.gsub(/_icon$/, ”)}.png”) end end Now the following call: <%= pencil_icon %> produces this image tag: <img src=”/images/silk/pencil.png” />

Composing DSLs in JavaScript

Further to my previous post I thought I’d share the approach I’ve been using to compose DSLs in JavaScript. If you want a more involved example, check out the currently in-development Forms module for Ojay. For this example I’m going to be writing a simple permissions language that sets up rules about when certain methods [...]

← Before After →