From d921b799747aacb47dc8bbca9b2eefe25159e9d5 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 23 Jan 2006 06:40:43 +0000 Subject: Add Object#instance_exec and Proc#bind git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3469 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/object_and_class_ext_test.rb | 6 ++++++ activesupport/test/core_ext/proc_test.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 activesupport/test/core_ext/proc_test.rb (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 22e4c6b8b4..fc19183ede 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -111,4 +111,10 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase object.instance_variable_set :@b, 2 assert_equal({'a' => 1, 'b' => 2}, object.instance_values) end + + def test_instance_exec_passes_arguments_to_block + block = Proc.new { |value| [self, value] } + assert_equal %w(hello goodbye), 'hello'.instance_exec('goodbye', &block) + end + end diff --git a/activesupport/test/core_ext/proc_test.rb b/activesupport/test/core_ext/proc_test.rb new file mode 100644 index 0000000000..ca91a257b7 --- /dev/null +++ b/activesupport/test/core_ext/proc_test.rb @@ -0,0 +1,12 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/proc' + +class ProcTests < Test::Unit::TestCase + def test_bind_returns_method_with_changed_self + block = Proc.new { self } + assert_equal self, block.call + bound_block = block.bind("hello") + assert_not_equal block, bound_block + assert_equal "hello", bound_block.call + end +end \ No newline at end of file -- cgit v1.2.3