Project

General

Profile

Actions

Feature #8391

closed

Introduce Object.singleton_method(:sym)

Added by stephenmurdoch (stephen murdoch) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Target version:
[ruby-core:54914]

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 # => #<UnboundMethod: A#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

Updated by nobu (Nobuyoshi Nakada) over 11 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) over 11 years ago

I like this idea.

Matz.

Actions #3

Updated by naruse (Yui NARUSE) over 11 years ago

  • Target version set to 2.1.0
Actions #4

Updated by nobu (Nobuyoshi Nakada) over 11 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]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0