Feature #8614

Object#singleton_class with a block

Added by Tsuyoshi Sawada 9 months ago. Updated 9 months ago.

[ruby-core:55880]
Status:Open
Priority:Normal
Assignee:-
Category:-
Target version:-

Description

=begin
Most of the time when I use Object#singleton_class, I use it with class_eval following it, like follows:

class Foo
  singleton_class.class_eval{attr_accessor :bar}
end

I think it would be convenient if Object#singleton_class can optionally take a block so that the following will mean the same as above.

class Foo
  singleton_class{attr_accessor :bar}
end

=end

History

#1 Updated by Elliot Winkler 9 months ago

I'm not sure I like this, but I do agree about the use case. What about adding a method singleton_class_eval instead?

Also available in: Atom PDF