Class: Location
- Inherits:
-
Object
- Object
- Location
- Defined in:
- lib/locationclass.rb
Overview
Represents a 2D location in space. Note that there is an attr_accessor for @x and @y.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
-
#highest_value_x? ⇒ Boolean
Returns true if @x > @y.
-
#highest_value_y? ⇒ Boolean
Returns true if @y > @x.
-
#initialize(x, y) ⇒ Location
constructor
Sets the x and y to the given values.
-
#lowest_value_x? ⇒ Boolean
Returns true unless @x > @y.
-
#lowest_value_y? ⇒ Boolean
Returns true unless @y > @x.
-
#move(x, y) ⇒ Object
Increases the x and y by the given amounts.
-
#moveNeg(x, y) ⇒ Object
Decreases the x and y by the given amounts.
-
#moveTo(x, y) ⇒ Object
Moves the location to the specified values.
Constructor Details
#initialize(x, y) ⇒ Location
Sets the x and y to the given values.
7 8 9 10 |
# File 'lib/locationclass.rb', line 7 def initialize(x, y) @x = x @y = y end |
Instance Method Details
#[](k) ⇒ Object
45 46 47 48 49 |
# File 'lib/locationclass.rb', line 45 def [](k) return nil unless (k == 0 or k == 1) return self.x() if (k == 0) return self.y() end |
#[]=(k, v) ⇒ Object
50 51 52 53 54 |
# File 'lib/locationclass.rb', line 50 def []=(k, v) return nil unless (k == 0 or k == 1) self.x = v if (k == 0) self.y = v end |
#highest_value_x? ⇒ Boolean
Returns true if @x > @y.
29 30 31 |
# File 'lib/locationclass.rb', line 29 def highest_value_x?() return @x > @y end |
#highest_value_y? ⇒ Boolean
Returns true if @y > @x.
33 34 35 |
# File 'lib/locationclass.rb', line 33 def highest_value_y?() return @y > @x end |
#lowest_value_x? ⇒ Boolean
Returns true unless @x > @y.
37 38 39 |
# File 'lib/locationclass.rb', line 37 def lowest_value_x?() return !highest_value_x?() end |
#lowest_value_y? ⇒ Boolean
Returns true unless @y > @x.
41 42 43 |
# File 'lib/locationclass.rb', line 41 def lowest_value_y?() return !highest_value_y?() end |
#move(x, y) ⇒ Object
Increases the x and y by the given amounts.
13 14 15 16 |
# File 'lib/locationclass.rb', line 13 def move(x, y) @x += x @y += y end |
#moveNeg(x, y) ⇒ Object
Decreases the x and y by the given amounts.
18 19 20 21 |
# File 'lib/locationclass.rb', line 18 def moveNeg(x, y) @x -= x @y -= y end |
#moveTo(x, y) ⇒ Object
Moves the location to the specified values.
23 24 25 26 |
# File 'lib/locationclass.rb', line 23 def moveTo(x, y) @x = x @y = y end |