What does Ruby syntax mean: if self <Class :: Name?

I came across this strange syntax that I had never seen before:

if self < Example::Class::Name
  # do something
else
  # do something else
end

What does this check?

+4
source share
2 answers

It checks if a selfsubclass isExample::Class::Name

Check out the Modular Docs :)

+4
source

Check superclass / subclass.

This checks if the Example::Class::Namesuperclass is selfsuch a declaration:

class DemonstrationClass < Example::Class::Name
  #de body of sub-class

  def cascade *parameters
     #de ...do work
     super #de passes all parameters to the same method name of the super-class.
           #de this even works on an initialize method declaration!
  end
end

Instances DemonstrationClassare subclasses of the superclass Example::Class::Name.

Subclasses have a special feature that allows you to do things such as what I showed in the method cascade, and much more.

:

+2

All Articles