Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add subclass_class

  • Loading branch information...
commit 1517ea8ce145e053e830f996fd613b0c6f79d629 1 parent 9fa0a9a
@rkh authored
View
11 README.md
@@ -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`
View
11 lib/convinius/subclass_class.rb
@@ -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
View
11 spec/subclass_class_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.