class PerfectShape::Square
Constants
- MESSAGE_WIDTH_AND_HEIGHT_AND_LENGTH_NOT_EQUAL
Attributes
length[R]
size[R]
Public Class Methods
new(x: 0, y: 0, length: nil, size: nil, width: nil, height: nil)
click to toggle source
Constructs with x, y, length (optionally width or height can be passed as alias for length)
Calls superclass method
PerfectShape::RectangularShape::new
# File lib/perfect_shape/square.rb, line 32 def initialize(x: 0, y: 0, length: nil, size: nil, width: nil, height: nil) raise MESSAGE_WIDTH_AND_HEIGHT_AND_LENGTH_NOT_EQUAL if (length && size && length != size) length ||= size 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
Public Instance Methods
height=(value)
click to toggle source
Calls superclass method
PerfectShape::RectangularShape#height=
# File lib/perfect_shape/square.rb, line 54 def height=(value) super self.length = @height unless length == @height self.width = @height unless width == @height end
length=(value)
click to toggle source
Sets length, normalizing to BigDecimal
# File lib/perfect_shape/square.rb, line 41 def length=(value) @length = BigDecimal(value.to_s) self.width = @length unless width == @length self.height = @length unless height == @length end
Also aliased as: size=
width=(value)
click to toggle source
Calls superclass method
PerfectShape::RectangularShape#width=
# File lib/perfect_shape/square.rb, line 48 def width=(value) super self.length = @width unless length == @width self.height = @width unless height == @width end