Permalink
Browse files

add subclass_class

  • Loading branch information...
1 parent 9fa0a9a commit 1517ea8ce145e053e830f996fd613b0c6f79d629 @rkh committed Feb 3, 2011
Showing with 33 additions and 0 deletions.
  1. +11 −0 README.md
  2. +11 −0 lib/convinius/subclass_class.rb
  3. +11 −0 spec/subclass_class_spec.rb
View
@@ -45,6 +45,17 @@ A more realistic example:
include Awesome
end
+Creating own subclass of Class
+------------------------------
+in: `convinius/subclass_class`
+
+ class MyClass < Class
+ end
+
+ Foo = MyClass.new Bar
+ Foo.new.class # => Foo
+ Foo.class # => MyClass (without patch this would be Class)
+
Import constants from Rubinius
------------------------------
in: `convinius/globals`
@@ -0,0 +1,11 @@
+module Convinius
+ module SubclassClass
+ extend_object Class
+
+ def new(*)
+ result = super
+ Rubinius::Unsafe.set_class result, self if self != Class
+ result
+ end
+ end
+end
@@ -0,0 +1,11 @@
+require 'convinius/subclass_class'
+require 'spec_helper'
+
+describe Convinius::SubclassClass do
+ it 'should allow using subclasses of Class' do
+ example = Class.new Class
+ klass = example.new
+ klass.new.class.should == klass
+ klass.class.should == example
+ end
+end

0 comments on commit 1517ea8

Please sign in to comment.