Bug #961
closed
a bug or a missleading documentation for Singleton module
Added by khelll (khaled alhabache) almost 16 years ago.
Updated over 13 years ago.
Description
=begin
require 'singleton'
class Klass
include Singleton
# ...
end
a,b = Klass.instance => [#Klass:0xebaf12]
b #=> nil
####################
a == b # => true¶
is that a bug or missleading documentation ???¶
###################
=end
=begin
I guess it should be
a = Klass.instance
b = Klass.instance
a == b # => true
If you look exactly, there are two Klass.instance on the right side - a multi-assignment. So the documentation is correct, but likely to be misunderstood by beginners.
=end
=begin
Hi,
In message "Re: [ruby-core:21029] [Bug #961] a bug or a missleading documentation for Singleton module"
on Thu, 1 Jan 2009 07:01:36 +0900, khaled alhabache redmine@ruby-lang.org writes:
|# in http://www.ruby-doc.org/stdlib/libdoc/singleton/rdoc/index.html
|# a == b # => true
|# is that a bug or missleading documentation ???
The text in the above document said (with properly formatted):
a,b = Klass.instance, Klass.instance
a == b # => true
a.new # NoMethodError - new is private …
Your input was:
|a,b = Klass.instance # => [#Klass:0xebaf12]
|b #=> nil
Now you can see the difference. You've typed single Klass.instance.
It apparently not a bug. You misread it, maybe because of missing
newlines in text from ruby-doc.org. I probably caused by missing
indentation in RDoc in signleton.rb. I will fix this.
matz.
=end
=begin
a,b = Klass.instance, Klass.instance
a == b # => true
a.new # NoMethodError - new is private …
Also, shouldn't the last line say "Klass.new"?
=end
=begin
Hi,
In message "Re: [ruby-core:21038] [Bug #961] a bug or a missleading documentation for Singleton module"
on Thu, 1 Jan 2009 20:10:06 +0900, Daniel Luz redmine@ruby-lang.org writes:
| a.new # NoMethodError - new is private …
|
|Also, shouldn't the last line say "Klass.new"?
Indeed. I will fix.
matz.
=end
- Status changed from Open to Closed
- Assignee set to matz (Yukihiro Matsumoto)
- ruby -v set to 1.9
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0