Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor __binding__ method

Refactor Object#__binding__ method in order to avoid repetitive code of
__binding_impl__. Use String variable for the __binding_impl__ method
definition to guarantee that class_eval and instance_eval evaluate the
same code.

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
  • Loading branch information...
commit c8fc0e52a35dcee5b854193e8561603de7d46b1d 1 parent e189538
@kyrylo kyrylo authored
Showing with 10 additions and 12 deletions.
  1. +10 −12 lib/pry/core_extensions.rb
View
22 lib/pry/core_extensions.rb
@@ -22,7 +22,7 @@ def pry(*args)
if args.first.is_a?(Hash) || args.length == 0
args.unshift(self)
end
-
+
Pry.start(*args)
end
@@ -32,19 +32,17 @@ def __binding__
return class_eval "binding"
end
- unless respond_to? :__binding_impl__
+ unless respond_to?(binding_impl = :__binding_impl__)
+ binding_impl_method = <<-METHOD
+ def #{binding_impl}
+ binding
+ end
+ METHOD
+
begin
- instance_eval %{
- def __binding_impl__
- binding
- end
- }
+ instance_eval binding_impl_method
rescue TypeError
- self.class.class_eval %{
- def __binding_impl__
- binding
- end
- }
+ self.class.class_eval binding_impl_method
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.