While building up the server side RPC methods for client side calls from ExtJS’s new Direct RPC framework, I thought it would be useful to fail fast whenever the client caller violated the interface contract. Enter fail fast.
def submit(params)
action = params.delete(:action)
id = params.delete(:id)
assert(action) {|v| [’update’, ‘create’].include?(v)}
…
Further up the [...]
When using this neat snippet from Dr Nic for testing a plugin I use internally, I came across the behavior described by Avdi. The proposed solution works great!
A single line modification to Dr Nic’s class ensures it works with class_inheritable_accessor from ActiveSupport.
def create_class(class_name, superclass, &block)
klass = Class.new superclass
klass.instance_eval &block
Object.const_set class_name, klass
end
While a hack, a dirty way of getting Juicer to merge JavaScript files at every load is the following, which I’m running under a custom Webrick setup:
# Shamelessly cheat so Juicer cannot close its copy of STDOUT
module Juicer
LOGGER.instance_eval do
def close ; end
end
end
# Later, far away in a custom handler
Juicer::Cli.run(%w[merge -s –force -o /tmp/output.js js/my.js])
# Unfortunately, [...]
Chef is an awesome tool for centralized management of systems and resources. Chef recipes are best consumed in a sandbox, first, before being deployed. Below, I describe a simple sandbox setup using VirtualBox and Debian Lenny.
Using VirtualBox, define a new virtual machine. I used the business card ISO to install a bare [...]
It’s hacks like these that grow my appreciation of Ruby.
array = []
array.extend(Module.new{
def append(value)
value.is_a?(Array) ? replace(self|value) : replace(self|self<<value)
end
})
In a plugin that mixes in functionality to many of my Rails models, I have a model array that I stick method names into. Some of the methods are preconfigured in the mixin itself. The rest are [...]