Skip to content
Browse files

Pull constants from ruby instead of defining in C

  • Loading branch information...
1 parent c80a7d7 commit 33ba3a4bcea4a53e16ad7053b798e5fdfa137dae @drbrain committed Mar 25, 2011
Showing with 16 additions and 8 deletions.
  1. +7 −5 ext/pasteboard/pasteboard.c
  2. +9 −3 lib/pasteboard.rb
View
12 ext/pasteboard/pasteboard.c
@@ -9,6 +9,8 @@
#define BUFSIZE 128
static VALUE cPB;
+static VALUE cPBType;
+static VALUE cPBTypeEncodings;
static VALUE ePBError;
static VALUE usascii_encoding;
static VALUE utf8_encoding;
@@ -254,10 +256,7 @@ pb_copy_item_flavor_data(VALUE self, VALUE identifier, VALUE flavor) {
free(buffer);
#if HAVE_RB_STR_ENCODE
- encodings = rb_const_get_at(
- rb_const_get_at(cPB, rb_intern("Type")), rb_intern("Encodings"));
-
- encoding = rb_hash_aref(encodings, flavor);
+ encoding = rb_hash_aref(cPBTypeEncodings, flavor);
rb_enc_associate(data, rb_to_encoding(encoding));
#endif
@@ -405,7 +404,10 @@ pb_put_item_flavor(VALUE self, VALUE id, VALUE flavor, VALUE data) {
void
Init_pasteboard(void) {
cPB = rb_define_class("Pasteboard", rb_cObject);
- ePBError = rb_define_class_under(cPB, "Error", rb_eRuntimeError);
+
+ cPBType = rb_const_get_at(cPB, rb_intern("Type"));
+ cPBTypeEncodings = rb_const_get_at(cPBType, rb_intern("Encodings"));
+ ePBError = rb_const_get_at(cPB, rb_intern("Error"));
#if HAVE_RB_STR_ENCODE
utf8_encoding = rb_enc_from_encoding(rb_utf8_encoding());
View
12 lib/pasteboard.rb
@@ -1,4 +1,3 @@
-require 'pasteboard/pasteboard'
require 'enumerator'
##
@@ -9,6 +8,12 @@
class Pasteboard
##
+ # Pasteboard error class
+
+ class Error < RuntimeError
+ end
+
+ ##
# Version of pasteboard
VERSION = '1.0'
@@ -148,7 +153,8 @@ def put item, id = 0
end
end
- autoload :Type, 'pasteboard/type'
-
end
+require 'pasteboard/type'
+require 'pasteboard/pasteboard'
+

0 comments on commit 33ba3a4

Please sign in to comment.
Something went wrong with that request. Please try again.