what does :
mean in private :getWidth, :getHeight
?
# define private accessor methods
def getWidth
@width
end
def getHeight
@height
end
# make them private
private :getWidth, :getHeight
what does :
mean in private :getWidth, :getHeight
?
# define private accessor methods
def getWidth
@width
end
def getHeight
@height
end
# make them private
private :getWidth, :getHeight
The :
sigil in Ruby denotes a symbol. Symbols are immutable strings which are used as identifiers all over the Ruby language.
private :getWidth, :getHeight
Sets the visibility of the getWidth and getHeight method to private. Its an alternative way of writing:
private
def getWidth
@width
end
def getHeight
@height
end
Beyond that this code is very unidiomatic. Getter methods in Ruby should not be prefixed and method names should always be snake_case
and not camelCase
.
private
def width
@width
end
def height
@height
end
Or:
private
attr_reader :height, :width