Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Trying to mimic "method missing" in Node.js. Purpose: Allow snake case always. Problem: Don't seem to be possible to forward argument attributes?
var inspect = require('eyes').inspector({
styles: {
all: 'cyan',
label: 'underline',
other: 'inverted',
key: 'bold',
special: 'grey',
string: 'green',
number: 'magenta',
bool: 'blue',
regexp: 'green'
function missinMethod() {
// Mimic "method_missing" in Ruby.
process.on('uncaughtException', function(err) {
if (err.arguments.length) {
var method_name = err.arguments[0],
method_name_camel_case = method_name.replace(/(_[a-z0-9])/mg, function(a) { return a.replace('_', '').toUpperCase(); })
if (typeof eval(method_name_camel_case) === 'function') {
console.log("Proxy method: %s => %s", method_name, method_name_camel_case);
eval(method_name_camel_case + '()');
} else {
console.log("No such method: %s => %s", method_name, method_name_camel_case)
// skip
missin_method("foo", "bar");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.