Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/method_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def class_comment
return comment
end

if class_inst_or_module.respond_to?(:name)
if class_inst_or_module.is_a?(Module)
const_name = class_inst_or_module.name
else
const_name = class_inst_or_module.class.name
Expand Down
11 changes: 11 additions & 0 deletions spec/method_source_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
require 'spec_helper'

# Documentation for a class whose instances define #name.
class MethodSourceNamedInstance
def name; "instance name"; end
def work; end
end

describe MethodSource do

describe "source_location (testing 1.8 implementation)" do
Expand Down Expand Up @@ -96,6 +102,11 @@

# if RUBY_VERSION =~ /1.9/ || is_rbx?
describe "Lambdas and Procs" do
it "uses the class for a named ordinary instance" do
comment = MethodSourceNamedInstance.new.method(:work).class_comment
expect(comment).to eq("# Documentation for a class whose instances define #name.\n")
end

it 'should return source for proc' do
expect(MyProc.source).to eq(@proc_source)
end
Expand Down