4

I came across this strange syntax I have never seen before:

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

What does this check?

Andrew
  • 227,796
  • 193
  • 515
  • 708

2 Answers2

4

It checks if self is a subclass of Example::Class::Name

Check out the Module docs :)

Ju Liu
  • 3,939
  • 13
  • 18
2

Superclass / Sub-class check.

This is checking if Example::Class::Name is the superclass of self by this sort of 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 of DemonstrationClass are sub-classes of the Example::Class::Name super class.

Sub-classes have the special feature of being able do things like what I showed in the cascade method, and many more things.

Related questions with more sample code, and examples of associated concepts involved:

Community
  • 1
  • 1
digitalextremist
  • 5,952
  • 3
  • 43
  • 62