Created
August 21, 2009 16:02
-
-
Save lifo/172140 to your computer and use it in GitHub Desktop.
This file contains 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
[lifo@null rock (master)]$ ruby extconf.rb && make | |
[lifo@null rock (master)]$ ruby run.rb |
This file contains 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 'mkmf' | |
extension_name = 'rock' | |
dir_config(extension_name) | |
create_makefile(extension_name) |
This file contains 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" | |
#include "node.h" | |
static ID hook_method; | |
void method_call(rb_event_t event, NODE *node, VALUE self, ID id, VALUE klass) { | |
char * called_method; | |
called_method = rb_id2name(id); | |
VALUE hook_exists = rb_obj_respond_to(self, hook_method, Qtrue); | |
if(hook_exists == Qtrue && strcmp(called_method, "method_call_hook") != 0) { | |
rb_funcall(self, hook_method, 0); | |
} | |
} | |
void Init_rock() { | |
hook_method = rb_intern("method_call_hook"); | |
rb_add_event_hook(&method_call, RUBY_EVENT_CALL); | |
} |
This file contains 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 'rock' | |
class Hello | |
def world | |
end | |
def method_call_hook | |
puts "My bloody hook" | |
end | |
end | |
h = Hello.new | |
h.world |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment