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.
<!DOCTYPE html> | |
<html ng-app="App"> | |
<head> | |
<meta name="description" content="AngularJS + jQuery UI Drag-n-Drop" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.1/angular.min.js"></script> | |
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> | |
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap.min.css" rel="stylesheet"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script> | |
<meta charset=utf-8 /> |
class TasksController < ApplicationController | |
def update | |
tracker = TaskTracker.new(@task) | |
if @task.update_attributes(params[:task]) | |
TaskPusher.new(tracker, socket_id).push_changes | |
TaskMailSender.new(tracker, current_user).deliver_email | |
# success response | |
else | |
# failure respond | |
end |
<?php | |
trait MetaClass | |
{ | |
protected $__classMethods = array(); | |
static protected $__staticMethods = array(); | |
public function __call($name, $args) | |
{ |
module Constraint | |
class Staff | |
def matches?(request) | |
warden(request).authenticated? && | |
warden(request).user.staff? | |
end | |
private |
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
config.before(:each) do | |
DatabaseCleaner.strategy = :transaction | |
end | |
config.before(:each, js: true) do |
/* | |
* Selenium WebDriver JavaScript test with Mocha and NodeJS | |
* | |
* Start with: SELENIUM=PATH_TO_SELENIUM_JAR/selenium-server-standalone-2.31.0.jar mocha -t 10000 -R list google-sample.js | |
* | |
* Download selenium-server-standalone-2.31.0.jar from https://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar | |
* 'sudo su' and 'npm install -g colors mocha selenium-webdriver' | |
* | |
* http://visionmedia.github.io/mocha/ | |
* https://code.google.com/p/selenium/wiki/WebDriverJs |
// Don't care much about inheritance at this point, but I'll probably attempt it at | |
// some point via cloning ancestor schema's | |
var mongoose = require('mongoose'), | |
Schema = mongoose.Schema; | |
var Contact = new Schema({ | |
_type: String, | |
name: String | |
}); |