Skip to content

Instantly share code, notes, and snippets.

View mark's full-sized avatar
💭
Smoove

Mark Josef mark

💭
Smoove
View GitHub Profile
@mark
mark / my_date.rb
Created April 13, 2011 15:44
This was the date class I wrote like 5 years ago
class MyDate
include Comparable
MyDatesInMonth = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
MonthsOfYear = [nil, :January, :February, :March, :April, :May, :June,
:July, :August, :September, :October, :November, :December]
MyDatesOfWeek = [:Sunday, :Monday, :Tuesday, :Wednesday, :Thursday, :Friday, :Saturday]
def initialize(year, month, day, fixed = true)

An exploration of "dependency injection" in ruby

I recently came across this reddit, demo'ing "dependency injection and inversion of control" in what I think is C#/.Net?

It resulted in a predictable spate of comments on reddit saying basicaly "oh my gosh, dependency injection is so evil, just look at that."

But it got me thinking about how I'd handle the same issues in ruby, and I think the issues to be handled are real issues. So let's look at that.

I don't understand the (.Net?) framework being used in the original example, and I don't feel like reproducing an app environment that would do similar in ruby, so let's just stick to the heart of the matter. They've got some class (not entirely sure which one it is in their tree) that has a method that processes payments, translating that method into ruby it looks something like this:

# coding: utf-8
# Can ruby have method names have newlines/be crazy?
class BadKitty
FACE = "
|\\_/|
/ @ @ \\
( > º < )
`>>x<<´
@zobar
zobar / .gitignore
Last active December 24, 2015 04:09
Option monad in Ruby
.rbenv-gemsets
@teliosdev
teliosdev / rbinit_project.rb
Last active December 25, 2015 08:09
Creates a basic project for creating a ruby library.
#!/usr/bin/env ruby
require 'fileutils'
def init_project(project_name, user_name, user_email, directory)
project_directory = File.join(directory,
project_name.gsub("-", "/")).gsub("./", "")
project_const = project_name.gsub(/_([a-z])/) do |match|
@zobar
zobar / .gitignore
Last active December 28, 2015 01:29
Dimensional analysis in Scala
/project
/target
@zobar
zobar / .gitignore
Last active December 30, 2015 16:59
Chip: composable vector operations in Ruby.
/.yardoc
/.yardopts
/coverage
/doc
@dblandin
dblandin / Rakefile
Last active June 17, 2016 15:30 — forked from ParkinT/Rakefile
RubyMotion Configuration and Deploy/Release
# -*- coding: utf-8 -*-
$:.unshift('/Library/RubyMotion/lib')
require 'motion/project/template/ios'
require 'bundler'
Dir.glob('./config/*.rb').each { |file| require file }
if ARGV.join(' ') =~ /spec/
Bundler.require :default, :development, :spec
elsif ARGV.join(' ') =~ /testflight/
require 'rubygems'
require 'nokogiri'
class MyFilter
def ends_with set, ends
set.map { |x| x.to_s }.join.end_with? ends
end
end
doc = Nokogiri.XML(DATA)