Class: RubyAnything::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-anything/cursor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject

Returns the value of attribute x.



5
6
7
# File 'lib/ruby-anything/cursor.rb', line 5

def x
  @x
end

#yObject

Returns the value of attribute y.



5
6
7
# File 'lib/ruby-anything/cursor.rb', line 5

def y
  @y
end

Instance Method Details

#clearObject



14
15
16
17
# File 'lib/ruby-anything/cursor.rb', line 14

def clear
  self.x = 0
  self.y = 0
end

#downObject



23
24
25
# File 'lib/ruby-anything/cursor.rb', line 23

def down
  self.y += 1
end

#leftObject



27
28
29
# File 'lib/ruby-anything/cursor.rb', line 27

def left
  self.x -= 1 if @minx < x
end

#rightObject



31
32
33
# File 'lib/ruby-anything/cursor.rb', line 31

def right
  self.x += 1
end

#upObject



19
20
21
# File 'lib/ruby-anything/cursor.rb', line 19

def up
  self.y -= 1 if @miny < y
end