Method: Array#flatten_splat!
- Defined in:
- lib/justools/core_ext/array/flatten_splat.rb
#flatten_splat! ⇒ Object
flatten_splat! is used for dealing conveniently with the common pattern where a method’s arguments has a splat (*) operator, but the developer wants to provide the option of the method accepting either a list or an array for the argument.
Examples
Before: Now:
def do_something(*args) def do_something(*args)
if args.one? && args[0].is_a?(Array) args.flatten_splat!
args = args.shift end
end
end
15 16 17 |
# File 'lib/justools/core_ext/array/flatten_splat.rb', line 15 def flatten_splat! flatten_splat(true) end |