Skip to content

Instantly share code, notes, and snippets.

@irodkin
irodkin / DependencyInjectionInRuby.md
Created October 3, 2018 11:16 — forked from blairanderson/DependencyInjectionInRuby.md
Dependency Injection in Ruby. Originally from Jim Weirich’s blog which does not exist except for googles cache.

Dependency Injection in Ruby 07 Oct 04

Introduction

At the 2004 Ruby Conference, Jamis Buck had the unenviable task to explain Dependency Injection to a bunch of Ruby developers. First of all, Dependency Injection (DI) and Inversion of Control (IoC) is hard to explain, the benefits are subtle and the dynamic nature of Ruby make those benefits even more marginal. Furthermore examples using DI/IoC are either too simple (and don’t convey the usefulness) or too complex (and difficult to explain in the space of an article or presentation). I once attempted to explain DI/IoC to a room of Java programmers (see onestepback.org/articles/dependencyinjection/), so I can’t pass up trying to explain it to Ruby developers.

Thanks goes to Jamis Buck (the author of the Copland DI/IoC framework) who took the time to review this article and provide feedback.

What is Dependency Injection?

@irodkin
irodkin / js_func_definition.js
Created February 9, 2018 15:04
What's better - to define function inside object definition or outside?
if(App.app_settings.requests == undefined) App.app_settings.requests = {};
App.app_settings.requests.getAppData = function(id, settings){
this.apiRequest({
type: 'GET',
url: 'app_settings/getAppData',
data: {id: id},
error: settings.error,
success: settings.success
});