Use Array() to array-ify inputs in Ruby
Kernel#Array takes an argument and tries very hard to convert it into an Array.
Let’s look at some examples:
1 | Array([1,2,3]) # => [1,2,3] |
Using Kernel#Array can lead to very forgiving APIs.
Consider following method:
1 |
|
1 | log_reading(3.14) |
1 | [READING] 3.14 |
Conclusion
Kernel#Array is a go-to tool for coercing inputs into Array form.
I throw Kernel#Array and stop worrying about whether the input arrived in the expected form.