Skip to content

Commit

Permalink
Merge pull request #256 from dummey/array_flatten
Browse files Browse the repository at this point in the history
Array flatten
  • Loading branch information
ryanstout committed Jul 29, 2015
2 parents 9421743 + 0a10907 commit 3a5b146
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/volt/models/array_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ def +(*args)
super(*args)
end

def flatten(*args)
wrap_values(to_a.flatten(*args))
end

def new_model(*args)
Volt::Model.class_at_path(options[:path]).new(*args)
end
Expand Down
10 changes: 10 additions & 0 deletions spec/models/array_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@
Volt::Computation.flush!
expect(count).to eq(2)
end

it 'should flatten' do
array = Volt::ArrayModel.new([])

array << Volt::ArrayModel.new([Volt::ArrayModel.new([1,2]), Volt::ArrayModel.new([3])])
array << Volt::ArrayModel.new([Volt::ArrayModel.new([4,5]), Volt::ArrayModel.new([6])])

expect(array.flatten.size).to eq(6)
expect(array.to_a.flatten.size).to eq(6)
end
end

0 comments on commit 3a5b146

Please sign in to comment.