Feature #8391

Introduce Object.singleton_method(:sym)

Added by stephen murdoch about 2 years ago. Updated about 2 years ago.

[ruby-core:54914]
Status:Closed
Priority:Normal
Assignee:Yukihiro Matsumoto

Description

=begin
In the code below:

module A
def self.hello end
def world end
end

We can reflect on the instance method like so:

A.instance_methods # => [:world]
A.instance_method :world # => #

It's neat, but when we come to the singleton:

A.singleton_methods # => [:hello]
A.singleton_method :hello # => undefined method `singleton_method' for A:Module

I find (({Object.singleton_method(:sym)})) more syntactically consistent than (({Object.method(:sym)})).
=end

Associated revisions

Revision 40684
Added by Nobuyoshi Nakada about 2 years ago

proc.c: Kernel#singleton_method

  • proc.c (rb_obj_singleton_method): new method Kernel#singleton_method which returns a Method object of the singleton method. non-singleton method causes NameError, but not aliased or zsuper method, right now. [Feature #8391]

Revision 40684
Added by Nobuyoshi Nakada about 2 years ago

proc.c: Kernel#singleton_method

  • proc.c (rb_obj_singleton_method): new method Kernel#singleton_method which returns a Method object of the singleton method. non-singleton method causes NameError, but not aliased or zsuper method, right now. [Feature #8391]

Revision 40725
Added by Yui NARUSE about 2 years ago

Add NEWS about Kernel#singleton_method r40684 [Feature #8391]

Revision 40725
Added by Yui NARUSE about 2 years ago

Add NEWS about Kernel#singleton_method r40684 [Feature #8391]

History

#1 Updated by Nobuyoshi Nakada about 2 years ago

  • Tracker changed from Bug to Feature
  • Description updated (diff)
  • Category changed from syntax to core

It's not a syntax issue.

#2 Updated by Yukihiro Matsumoto about 2 years ago

I like this idea.

Matz.

#3 Updated by Yui NARUSE about 2 years ago

  • Target version set to 2.1.0

#4 Updated by Nobuyoshi Nakada about 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r40684.
stephen, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


proc.c: Kernel#singleton_method

  • proc.c (rb_obj_singleton_method): new method Kernel#singleton_method which returns a Method object of the singleton method. non-singleton method causes NameError, but not aliased or zsuper method, right now. [Feature #8391]

Also available in: Atom PDF