Module: Size

Included in:
Dimensions
Defined in:
tomes/spells/geometry/size.rb

Overview

A module for dealing with an object’s height (occasionally called “length”) and width. It is recommended you use #width and #height instead of #w or #h.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#heightObject Also known as: h

The object’s length along the Y-axis.



11
# File 'tomes/spells/geometry/size.rb', line 11

attr_accessor :width, :height

#widthObject Also known as: w

The object’s length along the X-axis.



11
12
13
# File 'tomes/spells/geometry/size.rb', line 11

def width
  @width
end

Instance Method Details

#adjust_size(size_offset) ⇒ Void Also known as: grow

Adds the size_offset[0, 1] to the width and height respectively.

Parameters:

  • size_offset (Array<Integer, Integer>)

Returns:

  • (Void)


26
27
28
29
# File 'tomes/spells/geometry/size.rb', line 26

def adjust_size(size_offset)
  self.width += size_offset[0]
  self.height += size_offset[1]
end

#sizeArray<Integer, Integer> Also known as: proportions

Returns an array containing the object’s width and height attributes.

Returns:

  • (Array<Integer, Integer>)


34
35
36
# File 'tomes/spells/geometry/size.rb', line 34

def size
  [width, height]
end

#size=(new_size) ⇒ Void

Sets the width and height.

Parameters:

  • new_size (Array<Integer, Integer>)

Returns:

  • (Void)


19
20
21
# File 'tomes/spells/geometry/size.rb', line 19

def size=(new_size)
  self.width, self.height = new_size
end