This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (expect actual expectation expected) | |
| (display "• ") | |
| (display actual) | |
| (display " should equal ") | |
| (display expected) | |
| (display ": ") | |
| (expectation actual expected) | |
| (display "pass\n") | |
| ) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace CSharpTestFramework | |
| { | |
| class MainClass | |
| { | |
| private uint run; | |
| private uint failures; | |
| delegate void Test(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (my-for-each proc values) | |
| (if (null? values) | |
| #t | |
| (let () | |
| (proc (car values)) | |
| (my-for-each proc (cdr values))))) | |
| (my-for-each (lambda (x) (display x) (newline)) (list 1 3 999 3.14)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (my-for-each proc values) | |
| (if (null? values) | |
| #t | |
| (let () | |
| (proc (car values)) | |
| (my-for-each proc (cdr values))))) | |
| (import srfi-1) | |
| (use srfi-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Foo | |
| class << self | |
| def bar | |
| "Foo.bar" | |
| end | |
| end | |
| def bar | |
| self.class.bar | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Proc | |
| def method_missing(name, *args) | |
| self[name, *args] | |
| end | |
| end | |
| MyCrazyClass = ->(message, *args) { | |
| case message | |
| when :new | |
| ->(message, *args) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| desc "Remove trailing whitespace for source files" | |
| task :strip_whitespace do | |
| files = %w[ .autotest .rspec .rvmrc Gemfile ] | |
| globs = %w[ lib/**/*.rb spec/**/*.rb ] | |
| files_from_globs = globs.map { |glob| Dir[glob] } | |
| files_to_strip = (files + files_from_globs).flatten | |
| system "sed -e 's/[ \t]*$//' -i '' #{files_to_strip.join(" ")}" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rspec' | |
| class Cow | |
| class << self | |
| def method_missing(message) | |
| new(message.to_s) | |
| end | |
| end | |
| attr_reader :name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| messages = [ "one,two,three", "un,deux,trois", "eins,zwei,drei" ] | |
| File.open("messages.csv", "w") do |file| | |
| messages.each do |message| | |
| file.puts message | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'sequel' | |
| require 'rgl/adjacency' | |
| require 'rgl/topsort' | |
| require 'rgl/transitiv_closure' | |
| require 'rgl/connected_components' | |
| # Usage example below | |
| class DatabaseEmptier |