Feature #1431

Object#__class__

Added by svoop (Sven Schwyn) about 3 years ago. Updated about 1 year ago.

[ruby-core:23355]
Status:Rejected Start date:05/04/2009
Priority:Low Due date:
Assignee:matz (Yukihiro Matsumoto) % Done:

0%

Category:core
Target version:2.0.0

Description

Consider the following code using class instance variables:

class Car
  def self.total_count=(n)
    @total_count = n
  end

  def initialize
    self.class.total_count = 0
  end
end

The compile requires "self.class.total_count" as the more readable "class.total_count" is mistaken by the parser as a faulty class definition.

How about adding a __class__ method to Object?

class Object
  def __class__
    self.class
  end
end

It would allow the use of "__class__" as a de facto prefix for class instance variables and would fit e.g. the id/__id__ and send/__send__ paradigm.

History

Updated by yugui (Yuki Sonoda) almost 3 years ago

  • Assignee set to matz (Yukihiro Matsumoto)
  • Priority changed from Normal to Low
  • Target version set to 2.0.0

Updated by marcandre (Marc-Andre Lafortune) over 2 years ago

-1 because:

a) __class__ is more keystrokes (if you count the shift key)
b) self.class is clear (and exists currently)
c) I feel that __something__ should ideally be reserved for special cases; self.class isn't. I am aware that __FILE__ was used a lot before and there's talk about __dir__, but I think that require_relative is now a better solution for most of these cases.

Updated by naruse (Yui NARUSE) over 2 years ago

  • Status changed from Open to Rejected

Also available in: Atom PDF