Module: Rumai::Chain

Included in:
Area, Client, View
Defined in:
lib/rumai/wm.rb

Overview

Note:

Inheritors must override the #chain method.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) near(array, target, offset)

Fetches the object at the given offset from the given target object in the given array.



69
70
71
72
73
# File 'lib/rumai/wm.rb', line 69

def self.near array, target, offset
  if index = array.index(target)
    array[(index + offset) % array.length]
  end
end

+ (Object) next(array, target)

Fetches the object that comes after the given target object in the given array.



61
62
63
# File 'lib/rumai/wm.rb', line 61

def self.next array, target
  near array, target, +1
end

+ (Object) prev(array, target)

Fetches the object that comes before the given target object in the given array.



53
54
55
# File 'lib/rumai/wm.rb', line 53

def self.prev array, target
  near array, target, -1
end

Instance Method Details

- (Object) chain

Returns an array of objects related to this one.



31
32
33
# File 'lib/rumai/wm.rb', line 31

def chain
  [self]
end

- (Object) next

Returns the object after this one in the chain.



45
46
47
# File 'lib/rumai/wm.rb', line 45

def next
  Chain.next chain, self
end

- (Object) prev

Returns the object before this one in the chain.



38
39
40
# File 'lib/rumai/wm.rb', line 38

def prev
  Chain.prev chain, self
end