lib/knj/arrayext.rb in knjrbfw-0.0.42 vs lib/knj/arrayext.rb in knjrbfw-0.0.43
- old
+ new
@@ -228,6 +228,22 @@
end
end
return hash
end
+
+ #Forces an array to have a certain amount of columns.
+ #===Examples
+ # arr = [1, 2, 3, 4, 5]
+ # Knj::ArrayExt.force_no_cols(:arr => arr, :no => 4) #=> [1, 2, 3, 4]
+ def self.force_no_cols(args)
+ while args[:arr].length > args[:no]
+ args[:arr].slice!(-1)
+ end
+
+ while args[:arr].length < args[:no]
+ args[:arr] << args[:empty]
+ end
+
+ return nil
+ end
end
\ No newline at end of file