Class Index [+]

Quicksearch

Ramaze::CoreExtensions::Array

Extensions for Array

Public Instance Methods

put_after(element, object) click to toggle source

a = [1, 2, 3] a.put_after(2, 4) a # => [1, 2, 4, 3]

    # File lib/ramaze/snippets/array/put_within.rb, line 22
22:       def put_after(element, object)
23:         return self[index(element) + 1, 0] = object if include?(element)
24: 
25:         raise ArgumentError, "The given element doesn't exist"
26:       end
put_before(element, object) click to toggle source

a = [1, 2, 3] a.put_before(2, 4) a # => [1, 4, 2, 3]

    # File lib/ramaze/snippets/array/put_within.rb, line 31
31:       def put_before(element, object)
32:         return self[rindex(element), 0] = object if include?(element)
33: 
34:         raise ArgumentError, "The given element doesn't exist"
35:       end
put_within(object, constrain) click to toggle source

a = [1, 2, 3] a.put_within(4, :after => 2, :before => 3) a # => [1, 2, 4, 3]

    # File lib/ramaze/snippets/array/put_within.rb, line 11
11:       def put_within(object, constrain)
12:         pre, post = constrain.values_at(:after, :before)
13: 
14:         return put_after(pre, object) if rindex(post) - index(pre) == 1
15: 
16:         raise ArgumentError, "Too many elements within constrain"
17:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.