aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/object_and_class.rb6
-rw-r--r--activesupport/lib/active_support/core_ext/proc.rb12
2 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/object_and_class.rb b/activesupport/lib/active_support/core_ext/object_and_class.rb
index 4856a9f5d5..d44afbd839 100644
--- a/activesupport/lib/active_support/core_ext/object_and_class.rb
+++ b/activesupport/lib/active_support/core_ext/object_and_class.rb
@@ -65,6 +65,12 @@ class Object #:nodoc:
def to_json
ActiveSupport::JSON.encode(self)
end
+
+ unless defined? instance_exec # 1.9
+ def instance_exec(*arguments, &block)
+ block.bind(self)[*arguments]
+ end
+ end
end
class Class #:nodoc:
diff --git a/activesupport/lib/active_support/core_ext/proc.rb b/activesupport/lib/active_support/core_ext/proc.rb
new file mode 100644
index 0000000000..2ca23f62ef
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/proc.rb
@@ -0,0 +1,12 @@
+class Proc #:nodoc:
+ def bind(object)
+ block, time = self, Time.now
+ (class << object; self end).class_eval do
+ method_name = "__bind_#{time.to_i}_#{time.usec}"
+ define_method(method_name, &block)
+ method = instance_method(method_name)
+ remove_method(method_name)
+ method
+ end.bind(object)
+ end
+end