Skip to content

Instantly share code, notes, and snippets.

@coreyhaines
coreyhaines / replacement.rb
Last active August 29, 2015 14:25
Basic templating - better way?
def render_template template, question:
template % {
:"question.text" => CGI::escapeHTML(question.display_text.to_s),
:"question.name" => CGI::escapeHTML(question.name.to_s),
:"question.email" => CGI::escapeHTML(question.email.to_s)
}
end
class Rectangle
attr_accessor :width, :height
def initialize(width, height)
self.width = width
self.height = height
end
def area
width * height
@coreyhaines
coreyhaines / string_tokenizer.rb
Created January 24, 2009 05:44
String Tokenizer Kata for Code Retreat
module StringTokenizer
VERSION = '0.0.1'
def tokenize(context)
self.gsub(/\$[^ ]*/) {|match|
context[match[1..-1].to_sym]
}
end
end
List<MyThing> things = new List<MyThing> {
new MyThing { DueDate = DateTime.Now.AddDays(1),
new MyThing { DueDate = DateTime.Now.AddDays(-14)}}
};
public static class ThingTestingUtilities {
public static Thing NewThing(this TestsThings tester, DateTime duedate) {
return new MyThing { DueDate = duedate};
}
}
List<MyThing> things = new List<MyThing> {
this.NewThing(DateTime.Now.AddDays(1)),
this.NewThing(DateTime.Now.AddDays(-14))
}
List<MyThing> things = new List<MyThing> {
this.NewThing().WithDueDate(DateTime.Now.AddDays(1)),
this.NewThing().WithDueDate(DateTime.Now.AddDays(-14))
}
public static class ThingTestingUtilities {
public static Thing NewThing(this TestsThings tester) {
return new MyThing;
}
public static Thing WithDueDate(this MyThing thing, DateTime duedate) {
thing.DueDate = duedate;
return thing;
}
List<MyThing> things = new List<MyThing> {
this.NewThing().WithAnOffsetDueDateInDays(1),
this.NewThing().WithAnOffsetDueDateInDays(-14)
}
List<MyThing> things = new List<MyThing> {
thing(DateTime.Now.AddDays(1)),
thing(DateTime.Now.AddDays(-14))
}