Issue #5552 has been updated by Thomas Sawyer.


If you know pad length is greater than the array length then: 

  [:a,:b,:c].insert(5, nil)

Not sure about "rjust" though. I suppose there is always:

  a.unshift(nil) until a.size == 5

Though that seems fairly inefficient.


----------------------------------------
Feature #5552: Array#ljust, Array#rjust
http://redmine.ruby-lang.org/issues/5552

Author: Tsuyoshi Sawada
Status: Feedback
Priority: Normal
Assignee: 
Category: 
Target version: 


I propose the following methods Array#ljust(length [, pad]), Array#rjust(length [, pad]), whose behaviour is analogous to String#ljust(length [, padstr]), String#rjust(length [, padstr]).

    [:a, :b, :c].ljust(2) #=> [:a, :b, :c]
    [:a, :b, :c].ljust(5) #=> [:a, :b, :c, nil, nil]
    [:a, :b, :c].ljust(5, :x) #=> [:a, :b, :c, :x, :x]


-- 
http://redmine.ruby-lang.org