Feature #8391

Introduce Object.singleton_method(:sym)

Added by stephen murdoch 12 months ago. Updated 12 months ago.

[ruby-core:54914]
Status:Closed
Priority:Low
Assignee:Yukihiro Matsumoto
Category:core
Target version:2.1.0

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.instancemethods # => [:world]
A.instance
method :world # => #

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

A.singletonmethods # => [: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 12 months ago

proc.c: Kernel#singleton_method

  • proc.c (rbobjsingletonmethod): new method Kernel#singletonmethod 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 11 months ago

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

History

#1 Updated by Nobuyoshi Nakada 12 months 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 12 months ago

I like this idea.

Matz.

#3 Updated by Yui NARUSE 12 months ago

  • Target version set to 2.1.0

#4 Updated by Nobuyoshi Nakada 12 months 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 (rbobjsingletonmethod): new method Kernel#singletonmethod 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