Class: RubyAnything::Cursor
- Inherits:
-
Object
- Object
- RubyAnything::Cursor
- Defined in:
- lib/ruby-anything/cursor.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #clear ⇒ Object
- #down ⇒ Object
-
#initialize(opt = {}) ⇒ Cursor
constructor
A new instance of Cursor.
- #left ⇒ Object
- #right ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize(opt = {}) ⇒ Cursor
Returns a new instance of Cursor.
7 8 9 10 11 12 |
# File 'lib/ruby-anything/cursor.rb', line 7 def initialize(opt = {}) @x = opt[:x] || 0 @y = opt[:y] || 0 @minx = opt[:minx] || 0 @miny = opt[:miny] || 0 end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
5 6 7 |
# File 'lib/ruby-anything/cursor.rb', line 5 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
5 6 7 |
# File 'lib/ruby-anything/cursor.rb', line 5 def y @y end |
Instance Method Details
#clear ⇒ Object
14 15 16 17 |
# File 'lib/ruby-anything/cursor.rb', line 14 def clear self.x = 0 self.y = 0 end |
#down ⇒ Object
23 24 25 |
# File 'lib/ruby-anything/cursor.rb', line 23 def down self.y += 1 end |
#left ⇒ Object
27 28 29 |
# File 'lib/ruby-anything/cursor.rb', line 27 def left self.x -= 1 if @minx < x end |
#right ⇒ Object
31 32 33 |
# File 'lib/ruby-anything/cursor.rb', line 31 def right self.x += 1 end |
#up ⇒ Object
19 20 21 |
# File 'lib/ruby-anything/cursor.rb', line 19 def up self.y -= 1 if @miny < y end |