Class: Rect

Inherits:
Object
  • Object
show all
Defined in:
lib/rgss3/rect.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Rect

Returns a new instance of Rect.



6
7
8
9
10
11
12
13
14
15
# File 'lib/rgss3/rect.rb', line 6

def initialize(*args)
  case args.size
  when 0
    empty
  when 4
    set(*args)
  else
    raise ArgumentError
  end
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



4
5
6
# File 'lib/rgss3/rect.rb', line 4

def height
  @height
end

#widthObject

Returns the value of attribute width.



4
5
6
# File 'lib/rgss3/rect.rb', line 4

def width
  @width
end

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/rgss3/rect.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/rgss3/rect.rb', line 4

def y
  @y
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



40
41
42
43
# File 'lib/rgss3/rect.rb', line 40

def ==(other)
  self.class == other.class && x == other.x && y == other.y &&
    width == other.width && height == other.height
end

#emptyObject



29
30
31
32
33
34
# File 'lib/rgss3/rect.rb', line 29

def empty
  @x = 0
  @y = 0
  @width = 0
  @height = 0
end

#hashObject



47
48
49
# File 'lib/rgss3/rect.rb', line 47

def hash
  [:rect, *to_a].hash
end

#set(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rgss3/rect.rb', line 17

def set(*args)
  case args.size
  when 1
    rect, = args
    @x, @y, @width, @height = *rect
  when 4
    @x, @y, @width, @height = *args
  else
    raise ArgumentError
  end
end

#to_aObject



36
37
38
# File 'lib/rgss3/rect.rb', line 36

def to_a
  [x, y, width, height]
end