Feature #8391

Introduce Object.singleton_method(:sym)

Added by stephenmurdoch (stephen murdoch) about 7 years ago. Updated about 7 years ago.

Target version:


In the code below:

module A
def self.hello end
def world 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)})).

Updated by nobu (Nobuyoshi Nakada) about 7 years ago

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

It's not a syntax issue.

Updated by matz (Yukihiro Matsumoto) about 7 years ago

I like this idea.



Updated by naruse (Yui NARUSE) about 7 years ago

  • Target version set to 2.1.0

Updated by nobu (Nobuyoshi Nakada) about 7 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. [ruby-core:54914] [Feature #8391]

Also available in: Atom PDF