shou2017.com
JP

Methods Frequently Asked in Ruby Silver Exam

Thu Mar 22, 2018
Sat Aug 10, 2024

Here is a summary of methods frequently asked in the Ruby Silver exam. Reference

concat(Array)

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.

concat(String)

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.

[改訂2版]Ruby技術者認定試験合格教本

See Also