Skip to content

Instantly share code, notes, and snippets.

@ileitch
Created February 18, 2012 19:47
Show Gist options
  • Select an option

  • Save ileitch/1860781 to your computer and use it in GitHub Desktop.

Select an option

Save ileitch/1860781 to your computer and use it in GitHub Desktop.
diff --git a/kernel/bootstrap/block_environment.rb b/kernel/bootstrap/block_environment.rb
index ccc91b4..c13e0a5 100644
--- a/kernel/bootstrap/block_environment.rb
+++ b/kernel/bootstrap/block_environment.rb
@@ -23,6 +23,8 @@ module Rubinius
end
class AsMethod < Executable
+ attr_reader :block_env
+
def self.new(block_env)
Rubinius.primitive :block_as_method_create
raise PrimitiveFailure, "BlockEnvironment::AsMethod.new failed"
@@ -59,6 +61,44 @@ module Rubinius
def defined_line
@block_env.line
end
+
+ def ==(other)
+ # Given the following code:
+ # class Foo
+ # p = Proc.new { :cool }
+ # define_method :a, p
+ # define_method :a, p
+ # end
+ # foo = Foo.new
+ # foo.method(:a)
+ # foo.method(:b)
+ #
+ # The Method instances for :a and :b have different
+ # BlockEnvironments as define_method dups the BE
+ # when given a Proc.
+ #
+ # The BEs are identical otherwise, except for the
+ # name of the CompiledMethod.
+
+ block_env.scope == other.block_env.scope &&
+ block_env.top_scope == other.block_env.top_scope &&
+ block_env.module == other.block_env.module &&
+ code_equal_except_name?(other.block_env.code)
+ end
+
+ def code_equal_except_name?(other_code)
+ code = block_env.code
+ code.iseq == other_code.iseq &&
+ code.stack_size == other_code.stack_size &&
+ code.local_count == other_code.local_count &&
+ code.required_args == other_code.required_args &&
+ code.total_args == other_code.total_args &&
+ code.splat == other_code.splat &&
+ code.literals == other_code.literals &&
+ code.lines == other_code.lines &&
+ code.file == other_code.file &&
+ code.local_names == other_code.local_names
+ end
end
end
end
diff --git a/kernel/common/block_environment.rb b/kernel/common/block_environment.rb
index 45b6912..69a7962 100644
--- a/kernel/common/block_environment.rb
+++ b/kernel/common/block_environment.rb
@@ -8,6 +8,7 @@ module Rubinius
class BlockEnvironment
attr_reader :scope
attr_reader :top_scope
+ attr_reader :module
# The CompiledMethod that implements the code for the block
attr_reader :code
diff --git a/spec/tags/19/ruby/core/method/eql_tags.txt b/spec/tags/19/ruby/core/method/eql_tags.txt
index 37953dc..8f28f6b 100644
--- a/spec/tags/19/ruby/core/method/eql_tags.txt
+++ b/spec/tags/19/ruby/core/method/eql_tags.txt
@@ -1,3 +1,2 @@
fails:Method#eql? returns true if a method was defined using the other one
-fails:Method#eql? returns true for methods defined using the same block/proc
fails:Method#eql? returns true for the same method missing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment