Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
$ ruby -e "p ObjectSpace.each_object(Class).select { |e| e.ancestors.include?(Enumerable) }"
[Enumerator::Generator, Enumerator, Struct::Tms, Dir, File, ARGF.class, IO, Range, Struct, Hash, Array]
Hi there!
Back in August, we started working on switching our payment and email
provider for Practicing Ruby. As part of that process, we disabled
payments for new subscribers and re-subscribers temporarily so that we
wouldn't send more people through the bad old process we used to have.
Our records show that you are one of about 400 people who received a
temporarily free account during this transition.
I'm happy to say that as of today (November 15), we are now able to
module Contractor
def precondition(method, &block)
constraint = Module.new do
define_method method do |*a,&b|
raise unless instance_exec(*a, b, &block)
super(*a, &b)
end
end
module Contractor
FailedContract = Class.new(StandardError)
class << self
attr_accessor :enabled
end
def precondition(method, &block)
constraint = Module.new do
define_method method do |*a,&b|
require "celluloid"
class Cell
include Celluloid
def initialize
@pheremone = 0
# .. other variables
end
## 1.9.3
>> RUBY_VERSION
=> "1.9.3"
>> Proc.new { |a,b| [a,b] }.call
=> [nil, nil]
>> proc { |a,b| [a,b] }.call
=> [nil, nil]
>> lambda { |a,b| [a,b] }.call
ArgumentError: wrong number of arguments (0 for 2)
module AntSim
class World
def initialize(size)
@size = size
@data = size.times.map { size.times.map { Cell.new(0,0) } }
end
def [](location)
x,y = location
module AntSim
class World
def initialize(size)
@size = size
@data = size.times.map { size.times.map { Cell.new(0,0,0) } }
end
def [](location)
x,y = location
@practicingruby
practicingruby / mrdi.md
Created December 19, 2012 22:29
Models, Roles, Decorators, and Interactions -- A modest proposal for a toned done version of DCI that isn't as janky as Concerns.

Models, Roles, Decorators, and Interactions

A modest alternative to DCI that might be worth further thought

One of the problems with advancing the discussion on DCI is that we lack a comparable alternative pattern that has the same goals, but favors a low ceremony approach. The closest thing we have to that is Rails concerns, but they are more like distant relatives of the DCI concepts rather than first cousins, and that makes comparisions between the two approaches not especially fruitful.

I am considering the idea of experimenting with my own paradigm that captures the intent and purity of DCI, but with the convenience of concerns. Please note that this is just the starting point of a conversation, it is NOT a promise of comercially available cold fusion or a cure for cancer. It's just a gist with an idea on it I'd like to hear your thoughts on.

What if we had a top-level topology that was split into Models, **Rol

require "open3"
Open3.popen3("cat") do |stdin, stdout|
stdin.puts("HAHAHAHHAA")
puts stdout.gets
end