diff options
author | Xavier Noria <fxn@hashref.com> | 2009-06-13 01:01:42 +0200 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-06-12 16:14:06 -0700 |
commit | d32965399ccfa2052a4d52b70db1bae0ca16830b (patch) | |
tree | 7f41b1846efd2d11d7ebff15a115cba02ad75f11 /activerecord | |
parent | 54a5446641e4386285231385700b95a223931bff (diff) | |
download | rails-d32965399ccfa2052a4d52b70db1bae0ca16830b.tar.gz rails-d32965399ccfa2052a4d52b70db1bae0ca16830b.tar.bz2 rails-d32965399ccfa2052a4d52b70db1bae0ca16830b.zip |
uses Object#metaclass and Object#class_eval in a few spots
[#2797 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/named_scope.rb | 3 |
3 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index c4d143ab05..1fc0c93732 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -11,6 +11,7 @@ require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/string/behavior' require 'active_support/core_ext/symbol' +require 'active_support/core_ext/object/metaclass' module ActiveRecord #:nodoc: # Generic Active Record exception class. @@ -2040,7 +2041,7 @@ module ActiveRecord #:nodoc: # end # end def define_attr_method(name, value=nil, &block) - sing = class << self; self; end + sing = metaclass sing.send :alias_method, "original_#{name}", name if block_given? sing.send :define_method, name, &block diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index a7be3539d5..467d955a49 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/object/metaclass' + module ActiveRecord class IrreversibleMigration < ActiveRecordError#:nodoc: end @@ -300,8 +302,7 @@ module ActiveRecord case sym when :up, :down - klass = (class << self; self; end) - klass.send(:alias_method_chain, sym, "benchmarks") + metaclass.send(:alias_method_chain, sym, "benchmarks") end ensure @ignore_new_methods = false diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 1b22fa5e24..dd2a90b8e5 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/array' require 'active_support/core_ext/hash/except' +require 'active_support/core_ext/object/metaclass' module ActiveRecord module NamedScope @@ -99,7 +100,7 @@ module ActiveRecord end end, &block) end - (class << self; self end).instance_eval do + metaclass.instance_eval do define_method name do |*args| scopes[name].call(self, *args) end |