Forum: Ruby Onion 0.0.1 Released

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0814ff69e309b033508b3c7f363236fd?d=identicon&s=25 Ian Trudel (backorder)
on 2009-03-28 10:13
Onion 0.0.1 has been released.

  gem install Onion

Homepage: http://rubyforge.org/projects/onion/
Blog{Ruby, Onion, etc..}: http://mecenia.blogspot.com/

Onion, or Array Onion, allows peeling an array like an onion. It shreds
one layer after another, from the outer inwards the inner nested array,
according to the given depth. Infinite depth (or greater than current
nested array depth) is equivalent to Array#flatten. It's a tiny and
modest gem...

Vote if you would like Onion for Hashes as well.
http://rubyforge.org/survey/survey.php?group_id=80...

== Usage Examples

    [1, 2, 3, 4, 5].depth       => 1
    [1, [2, [3, 4], 5]].depth   => 3
    [1, [2, [3, [4, 5]]]].depth => 4

    [1, [2, [3, [4, 5]]]].peel_until(1) => [1, 2, 3, 4, 5]
    [1, [2, [3, [4, 5]]]].peel_until(2) => [1, 2, 3, [4, 5]]
    [1, [2, [3, [4, 5]]]].peel_until(3) => [1, 2, [3, [4, 5]]]
    [1, [2, [3, [4, 5]]]].peel_until(4) => [1, [2, [3, [4, 5]]]]

    [1, [2, [3, 4], 5]].peel(1)   => [1, 2, [3, 4], 5]
    [1, [2, [3, 4], 5]].peel(2)   => [1, 2, 3, 4, 5]

    [1, [2, [3, [4, 5]]]].peel(1) => [1, 2, [3, [4, 5]]]
    [1, [2, [3, [4, 5]]]].peel(2) => [1, 2, 3, [4, 5]]
    [1, [2, [3, [4, 5]]]].peel(3) => [1, 2, 3, 4, 5]
This topic is locked and can not be replied to.