Skip to content
Browse files

Merge pull request #2158 from ryoqun/proc-fixes-lambda

More proc fixes
  • Loading branch information...
2 parents 92d453b + a8cb7ad commit f99d4bd8a1e69ec3f3c29a5825954c4b886717be @brixen brixen committed
View
6 kernel/common/proc18.rb
@@ -12,7 +12,11 @@ def to_s
file, line = @block.source_location
end
- "#<#{self.class}:0x#{self.object_id.to_s(16)}@#{file}:#{line}>"
+ if file and line
+ "#<#{self.class}:0x#{self.object_id.to_s(16)}@#{file}:#{line}>"
+ else
+ "#<#{self.class}:0x#{self.object_id.to_s(16)}>"
+ end
end
alias_method :inspect, :to_s
View
4 kernel/common/proc19.rb
@@ -105,7 +105,8 @@ def source_location
def inspect
file, line = source_location
- "#<#{self.class}:0x#{self.object_id.to_s(16)}@#{file}:#{line}>"
+ l = " (lambda)" if lambda?
+ "#<#{self.class}:0x#{self.object_id.to_s(16)}@#{file}:#{line}#{l}>"
end
alias_method :to_s, :inspect
@@ -114,5 +115,4 @@ def __yield__(*args, &block)
@bound_method.call(*args, &block)
end
end
-
end
View
2 spec/ruby/core/proc/shared/to_s.rb
@@ -17,7 +17,7 @@ def hello; end
Proc.new { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)@([^ ]*)\/to_s\.rb:17>$/
lambda { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)@([^ ]*)\/to_s\.rb:18 \(lambda\)>$/
proc { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)@([^ ]*)\/to_s\.rb:19>$/
- method("hello").to_proc.send(@method).should =~ /^#<Proc:([^ ]*?)@([^ ]*)\/to_s\.rb:15>$/
+ method("hello").to_proc.send(@method).should =~ /^#<Proc:([^ ]*?)@([^ ]*)\/to_s\.rb:15 \(lambda\)>$/
end
end
end
View
4 spec/ruby/optional/capi/proc_spec.rb
@@ -54,8 +54,8 @@
@prc.arity.should == -1
end
- it "returns a Proc instance correctly described in #ispect" do
- @prc.inspect.should =~ /^#<Proc:([^ ]*?)>$/
+ it "returns a Proc instance correctly described in #inspect without source location" do
+ @prc.inspect.should =~ /^#<Proc:([^ :@]*?)>$/
end
it "shouldn't be equal to another one" do

0 comments on commit f99d4bd

Please sign in to comment.
Something went wrong with that request. Please try again.