Back in 2007, somebody posted a question asking whether or not it is
possible to overload the constructor in Ruby. Someone else answered
that it is not possible to overload any method, not just the
constructor. Indeed, when I tried to overload the constructor in my own
code it did not work.
However, in the code for fxruby’s FXRegion class, the initialize method
is indeed overloaded, and it works! Why is that? Does it have
something to do with the Module?
Here is the code and the Web site from whence it came:
# Construct new empty region
def initialize; end
# Construct new region copied from region _r_ (another FXRegion
def initialize®; end
# Construct new region from rectangle _rect_ (an FXRectangle
def initialize(rect); end
# # Construct rectangle region, where (_x_, _y_) are the coordinates
# upper left-hand corner and (w, h) are its width and height.
def initialize(x, y, w, h); end
# # Construct polygon region from an array of points. Here, _points_
# an array of FXPoint instances.
def initialize(points, winding=false); end
Another question: Why are there semicolons in the code? Is this really