Class: PerfectShape::Square
- Defined in:
- lib/perfect_shape/square.rb
Constant Summary collapse
- MESSAGE_WIDTH_AND_HEIGHT_AND_LENGTH_NOT_EQUAL =
'Square width, height, and length must all be equal if more than one is specified; or otherwise keep only one of them in arguments!'
Instance Attribute Summary collapse
-
#length ⇒ Object
Returns the value of attribute length.
Attributes included from RectangularShape
Attributes included from PointLocation
Instance Method Summary collapse
- #height=(value) ⇒ Object
-
#initialize(x: 0, y: 0, length: nil, width: nil, height: nil) ⇒ Square
constructor
Constructs with x, y, length (optionally width or height can be passed as alias for length).
- #width=(value) ⇒ Object
Methods inherited from Rectangle
Methods included from RectangularShape
Methods included from PointLocation
Methods inherited from Shape
#==, #bounding_box, #center_x, #center_y, #height, #max_x, #max_y, #min_x, #min_y, #normalize_point, #width
Constructor Details
#initialize(x: 0, y: 0, length: nil, width: nil, height: nil) ⇒ Square
Constructs with x, y, length (optionally width or height can be passed as alias for length)
31 32 33 34 35 |
# File 'lib/perfect_shape/square.rb', line 31 def initialize(x: 0, y: 0, length: nil, width: nil, height: nil) raise MESSAGE_WIDTH_AND_HEIGHT_AND_LENGTH_NOT_EQUAL if (length && width && length != width) || (length && height && length != height) || (width && height && width != height) length ||= width || height || 1 super(x: x, y: y, width: length, height: length) end |
Instance Attribute Details
#length ⇒ Object
Returns the value of attribute length.
28 29 30 |
# File 'lib/perfect_shape/square.rb', line 28 def length @length end |
Instance Method Details
#height=(value) ⇒ Object
50 51 52 53 54 |
# File 'lib/perfect_shape/square.rb', line 50 def height=(value) super self.length = value unless length == value self.width = value unless width == value end |
#width=(value) ⇒ Object
44 45 46 47 48 |
# File 'lib/perfect_shape/square.rb', line 44 def width=(value) super self.length = value unless length == value self.height = value unless height == value end |