On Thu, Aug 7, 2008 at 1:37 AM, Nobuyoshi Nakada <nobu / ruby-lang.org> wrote:
> Hi,
>
> At Wed, 6 Aug 2008 22:05:00 +0900,
> Otto Hilska wrote in [ruby-core:18148]:
>> It's still available for the scripts. For example, running in Rails
>> environment:
>>
>>  >> Object.subclasses
>> SyntaxError: (eval):1:in `subclasses_of': compile error
>> (eval):1: syntax error, unexpected tIDENTIFIER, expecting tCONSTANT
>> defined?(::fatal) && ::fatal.object_id == k.object_id
>>                  ^
>
> What do you mean by that error?

It's a method which searches ObjectSpace for subclasses of a set of
superclasses. It may find some classes which have been remove_const
but not garbage collected, so this eval checks whether the class is
'live'.

The full method:

  # Exclude this class unless it's a subclass of our supers and is defined.
  # We check defined? in case we find a removed class that has yet to be
  # garbage collected. This also fails for anonymous classes -- please
  # submit a patch if you have a workaround.
  def subclasses_of(*superclasses) #:nodoc:
    subclasses = []

    superclasses.each do |sup|
      ObjectSpace.each_object(class << sup; self; end) do |k|
        if k != sup && (k.name.blank? || eval("defined?(::#{k}) &&
::#{k}.object_id == k.object_id"))
          subclasses << k
        end
      end
    end

    subclasses
  end


>> If 'fatal' should not be used in scripts, changing the name should not
>> cause compatibility issues either. So what are the reasons for keeping
>> it lower-case?
>
> `fatal' means the case that user scripts can't/shouldn't
> raise/rescue it.
>
> First, why and how do you need it?

It's not used purposefully. The script above assumes that every Ruby
class has a valid Ruby name. It seems a fair assumption.

Best,
jeremy