Basically, just a wrapper like this:
class Array(T)
def self.wrap(e)
if e.is_a? Array
e
else
arr = Array(typeof(e)).new
arr << e
arr
end
end
end
p Array.wrap(100) # => [100]
p Array.wrap([100]) # => [100]
For Ruby, it just y = Array(x)
, for Rails, y = Array.wrap(x)
.
I found it more useful when porting ruby code to crystal, thanks.