Here is a summary of methods frequently asked in the Ruby Silver exam. Reference
array.concat(other_array)
The concat
method appends the elements of other_array
to the end of array
. It is a destructive method that modifies the receiver itself. The return value is the receiver itself.
fruits = ["apple", "orange", "banana"]
fruits.concat(["kiwi", "strawberry"])
p fruits
# Output: ["apple", "orange", "banana", "kiwi", "strawberry"]
This is a destructive method.
str.concat(other_str)
str.concat(integer)
The concat
method is an alias for <<
. It appends other_str
to the end of str
. If an integer is specified, it appends the corresponding character code as a single character to the end of str
.
s = "Hello"
s.concat(", world")
puts s
# Output: Hello, world
The fact that it is an alias for <<
is a common exam question.