somearray = ["некоторые", "вещь"]
anotherarray = ["другой", "вещь"]
somearray + anotherarray
As Boldewyn and Бен сказал, что text-align будет центрировать встроенные элементы (например, промежутки). Чтобы центрировать блочные элементы (такие как div, формы и абзацы), задайте ширину и установите для полей margin-right и margin-left значение auto.
Важно понимать разницу между блочными и встроенными элементами .
somearray = ["some", "thing"]
anotherarray = ["another", "thing"]
somearray.push anotherarray # => ["some", "thing", ["another", "thing"]]
#or
somearray << anotherarray # => ["some", "thing", ["another", "thing"]]
somearray.flatten! # => ["some", "thing", "another", "thing"]
somearray # => ["some", "thing", "another", "thing"]
У вас есть работоспособная идея, но #flatten!
находится не в том месте - он выравнивает свой приемник, поэтому вы можете использовать его, чтобы превратить [1, 2, ['foo', 'bar']]
в [1,2, 'foo', 'bar']
.
Я, несомненно, забываю некоторые подходы, но вы можете объединить :
a1.concat a2
a1 + a2 # creates a new array, as does a1 += a2
или добавить / добавить :
a1.push(*a2) # note the asterisk
a2.unshift(*a1) # note the asterisk, and that a2 is the receiver
или splice :
a1[a1.length, 0] = a2
a1[a1.length..0] = a2
a1.insert(a1.length, *a2)
или добавить и сгладить :
(a1 << a2).flatten! # a call to #flatten instead would return a new array
Вы можете просто использовать оператор +
!
http://ruby-doc.org/core/classes/Array.html
Попробуйте, он объединит ваши массивы, удаляя дубликаты
array1 = ["foo", "bar"]
array2 = ["foo1", "bar1"]
array3 = array1|array2
http://www.ruby-doc.org/core/classes/Array.html
Дополнительную документацию см. В «Set Union»
Вот два способа, обратите внимание, что в этом случае первый способ назначает новый массив (переводится как somearray = somearray + anotherarray)
somearray = ["some", "thing"]
anotherarray = ["another", "thing"]
somearray += anotherarray # => ["some", "thing", "another", "thing"]
somearray = ["some", "thing"]
somearray.concat anotherarray # => ["some", "thing", "another", "thing"]