mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
make sure Pry::Method#name returns a String.
This commit is contained in:
parent
c3ce60e749
commit
4dc9d27cf6
2 changed files with 13 additions and 2 deletions
|
@ -84,6 +84,12 @@ class Pry
|
|||
@method = method
|
||||
end
|
||||
|
||||
# Get the name of the method as a String, regardless of the underlying Method#name type.
|
||||
# @return [String]
|
||||
def name
|
||||
@method.name.to_s
|
||||
end
|
||||
|
||||
# @return [String, nil] The source code of the method, or `nil` if it's unavailable.
|
||||
def source
|
||||
@source ||= case source_type
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
require 'helper'
|
||||
|
||||
describe Pry::Method do
|
||||
it "should use String names for compatibility" do
|
||||
klass = Class.new { def hello; end }
|
||||
Pry::Method.new(klass.instance_method(:hello)).name.should == "hello"
|
||||
end
|
||||
|
||||
describe ".from_str" do
|
||||
it 'should look up instance methods if no methods available and no options provided' do
|
||||
klass = Class.new { def hello; end }
|
||||
|
@ -59,13 +64,13 @@ describe Pry::Method do
|
|||
it 'should look up methods using klass.new.method syntax' do
|
||||
klass = Class.new { def hello; :hello; end }
|
||||
meth = Pry::Method.from_str("klass.new.hello", Pry.binding_for(binding))
|
||||
meth.name.to_sym.should == :hello
|
||||
meth.name.should == "hello"
|
||||
end
|
||||
|
||||
it 'should look up instance methods using klass.meth#method syntax' do
|
||||
klass = Class.new { def self.meth; Class.new; end }
|
||||
meth = Pry::Method.from_str("klass.meth#initialize", Pry.binding_for(binding))
|
||||
meth.name.to_sym.should == :initialize
|
||||
meth.name.should == "initialize"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue