class LX::Array
A helper class to add methods to the Array
class. When you use the Array::lx you're creating an instance of LX::Array
.
Public Class Methods
new(p_arr)
click to toggle source
initialize a LX::Array
object. The only param is the array itself.
# File lib/lx.rb, line 196 def initialize(p_arr) @arr = p_arr end
Public Instance Methods
deep_dup()
click to toggle source
# File lib/lx.rb, line 245 def deep_dup return LX.deep_dup(@arr) end
draw()
click to toggle source
draw
# File lib/lx.rb, line 238 def draw rv = @arr[0] @arr.rotate! return rv end
move(old_idx, new_idx)
click to toggle source
Moves an array element from the old index to the new index.
arr = ['a', 'b', 'c'] arr.lx.move 1, 2 # => ["a", "c", "b"]
# File lib/lx.rb, line 203 def move(old_idx, new_idx) @arr.insert new_idx, @arr.slice!(1) end
split(exp)
click to toggle source
Splits an array into an array of arrays. The param is the delimiter.
arr = ['Fred', 'George', ':', 'Mary', 'Frank'] arr.lx.split ':' # => [["Fred", "George"], ["Mary", "Frank"]]
# File lib/lx.rb, line 210 def split(exp) # $tm.hrm rv = [] current = nil # loop through array looking for delimiter @arr.each do |el| if el == exp if current rv.push current current = nil end else current ||= [] current.push el end end # add last current if current rv.push current end # return return rv end