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
# Method instrumentation decorator with Ruby 2.1's new "method definition returns method name" feature | |
class Module | |
def instrument(notification_name, mid) | |
meth = instance_method(mid) | |
define_method(mid) { |*args, &bk| | |
ActiveSupport::Notifications.instrument(notification_name) do | |
meth.bind(self).call(*args, &bk) | |
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
all: rust-for-rubyists.epub site | |
rust-for-rubyists.epub: | |
pandoc --toc -S -s --epub-metadata=book/metadata.xml -o rust-for-rubyists.epub book/title.txt book/preamble.md book/chapter-*.md | |
site: | |
pandoc -S -s book/preamble.md book/chapter-*.md -o book/book.html --include-before-body=book/header.html --include-after-body=book/footer.html | |
pandoc -S -s book/chapter-01.md -o book/chapter-01.html --include-before-body=book/header.html --include-after-body=book/footer.html | |
pandoc -S -s book/chapter-02.md -o book/chapter-02.html --include-before-body=book/header.html --include-after-body=book/footer.html | |
pandoc -S -s book/chapter-03.md -o book/chapter-03.html --include-before-body=book/header.html --include-after-body=book/footer.html |
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
/************************************************ | |
eval.c - | |
$Author: matz $ | |
$Date: 1996/12/25 08:54:45 $ | |
created at: Thu Jun 10 14:22:17 JST 1993 | |
Copyright (C) 1993-1997 Yukihiro Matsumoto |
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 Module | |
def dispatch(*klasses, last) | |
last_klass, mid = last.first | |
klasses << last_klass | |
__dispatch_list << [klasses, instance_method(mid)] | |
define_method(mid, __dispatch_proc(__dispatch_list)) | |
end | |
def __dispatch_list | |
@__dispatch_list ||= [] |
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
#include <ruby.h> | |
typedef struct { | |
int foo; | |
} | |
my_data_t; | |
static void | |
my_data_mark(void* ptr) | |
{ |
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
/************************************************ | |
eval.c - | |
$Author: matz $ | |
$Date: 1996/12/25 08:54:45 $ | |
created at: Thu Jun 10 14:22:17 JST 1993 | |
Copyright (C) 1993-1997 Yukihiro Matsumoto |
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
def load_yaml_properly(yaml) | |
YAML.load yaml | |
rescue ArgumentError => e | |
raise e unless e.message =~ /undefined class\/module (.*)/ | |
$1.constantize | |
retry | |
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
chan = Channel.new | |
4.times do |i| | |
go 4.times { |j| | |
chan <- "#{i} #{j}" | |
} | |
end | |
16.times do | |
puts <-chan |
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
def filter_output! | |
r, w = IO.pipe | |
fork do | |
w.close | |
until r.eof? | |
line = r.gets | |
next if line =~ /^Started GET/ | |
puts line | |
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
module Kernel | |
def int(mid) | |
meth = instance_method(mid) | |
define_method(mid) { |*args, &bk| | |
val = meth.bind(self).call(*args, &bk) | |
raise TypeError, "#{mid} did not return an Integer" unless val.is_a? Integer | |
val | |
} | |
mid | |
end |