Skip to content

Commit

Permalink
Adding metaclass method for Rails/ActiveRecord 1.2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Jul 31, 2009
1 parent 3018799 commit a98a649
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/thinking_sphinx/rails_additions.rb
Expand Up @@ -134,3 +134,17 @@ def cattr_accessor(*syms)
Class.extend(
ThinkingSphinx::ClassAttributeMethods
) unless Class.respond_to?(:cattr_reader)

module ThinkingSphinx
module MetaClass
def metaclass
class << self
self
end
end
end
end

unless Object.new.respond_to?(:metaclass)
Object.send(:include, ThinkingSphinx::MetaClass)
end
12 changes: 12 additions & 0 deletions spec/lib/thinking_sphinx/rails_additions_spec.rb
Expand Up @@ -118,6 +118,18 @@
end
end

describe ThinkingSphinx::MetaClass do
describe 'metaclass' do
it "should exist as an instance method in Object" do
Object.new.should respond_to('metaclass')
end

it "should return the meta/eigen/singleton class" do
Object.new.metaclass.should be_a(Class)
end
end
end

class TestModel
@@squares = 89
@@circles = 43
Expand Down

0 comments on commit a98a649

Please sign in to comment.