Abusing the language:
batsman@tux-chan:/tmp$ expand -t 2 g.rb
class A
def self.method_added id
puts "Adding method #{id} to #{self}"
end
end
class A
def a
end
end
class A
p self.id
class << self
p self.id
def self.method_added id
p self.id
puts "Adding singleton method #{id} to #{self}"
end
end
end
class A
def self.a
end
end
batsman@tux-chan:/tmp$ ruby g.rb
Adding method a to A
538076252
538072582
I expected
Adding method a to A
538076252
538072582
XXXXXXXXX
Adding singleton method a to Class
Why is method_added not honored for singletons? Note it is perfectly
legal to define singletons' singleton methods:
>> class A
>> class << self
>> def self.foo
>> puts "foo"
>> end
>> end
>> end
=> nil
>> class << A; foo; end
foo
=> nil
POLS would mean for me that singletons' singletons should behave as "normal"
singletons or be completely unavailable.
--
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
<sct> Anyone want the new supermount? :)
<klogd> whats new aboutit
<sct> klogd: It cleans whiter than white. :)
-- Seen on #Linux