Forum: Ruby-dev [ruby-trunk - Feature #5552][Open] Array#ljust, Array#rjust

43421679c356f438c69bf6947e62c4ec?d=identicon&s=25 Tsuyoshi Sawada (Guest)
on 2011-11-02 19:27
(Received via mailing list)
Issue #5552 has been reported by Tsuyoshi Sawada.

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

Author: Tsuyoshi Sawada
Status: Open
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]
43421679c356f438c69bf6947e62c4ec?d=identicon&s=25 Tsuyoshi Sawada (Guest)
on 2011-11-03 10:02
(Received via mailing list)
Issue #5552 has been updated by Tsuyoshi Sawada.


And also `Array#center` analogous to `String#center` as well.
----------------------------------------
Feature #5552: Array#ljust, Array#rjust
http://redmine.ruby-lang.org/issues/5552

Author: Tsuyoshi Sawada
Status: Open
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]
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2011-11-03 11:38
(Received via mailing list)
Issue #5552 has been updated by Yukihiro Matsumoto.

Status changed from Open to Feedback

なぜそれが必要なのか提案に含めてください。Stringにあるから、では不十分です。
私にはArray#ljustなどがあって嬉しい局面が想像できません。
----------------------------------------
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]
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2011-11-06 09:03
(Received via mailing list)
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]
4828d528e2e46f7c8160c336eb332836?d=identicon&s=25 Robert Heiler (shevegen)
on 2011-11-07 00:20
I think this is a good suggestion.
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 yhara (Yutaka HARA) (Guest)
on 2012-10-27 16:56
(Received via mailing list)
Issue #5552 has been updated by yhara (Yutaka HARA).

Status changed from Feedback to Rejected

Hi,

I'm closing this ticket because of no feedback.
Please reopen if you still need these methods.
----------------------------------------
Feature #5552: Array#ljust, Array#rjust
https://bugs.ruby-lang.org/issues/5552#change-31810

Author: sawa (Tsuyoshi Sawada)
Status: Rejected
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]
This topic is locked and can not be replied to.