Created
February 26, 2013 19:00
-
-
Save adamhunter/5041075 to your computer and use it in GitHub Desktop.
Revisions
-
adamhunter created this gist
Feb 26, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ require 'mkmf' have_header('ruby.h') or missing('ruby.h') dir_config("ivar") create_makefile("ivar") 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ ruby extconf.rb && make && irb -I . -r ivar 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ #include "ruby.h" static VALUE rb_mIvar; static VALUE rb_ivar_iv_get(VALUE self, VALUE key) { return rb_ivar_get(self, rb_to_id(key)); } static VALUE rb_ivar_iv_set(VALUE self, VALUE key, VALUE value) { return rb_ivar_set(self, rb_to_id(key), value); } void Init_ivar() { rb_mIvar = rb_define_module("Ivar"); rb_define_method(rb_mIvar, "ivar_get", rb_ivar_iv_get, 1); rb_define_method(rb_mIvar, "ivar_set", rb_ivar_iv_set, 2); } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ $:.unshift('.') require 'ivar' Object.send(:include, Ivar) e = StandardError.new("foo") puts "Error message is: #{e.message}" e.ivar_set(:mesg, "bar") puts "Error message is: #{e.message}"