From: "trans (Thomas Sawyer)" Date: 2012-11-24T12:40:47+09:00 Subject: [ruby-core:49994] [ruby-trunk - Feature #7121] Extending the use of `require' Issue #7121 has been updated by trans (Thomas Sawyer). It's ugly, as it makes code harder to read. Please no. ---------------------------------------- Feature #7121: Extending the use of `require' https://bugs.ruby-lang.org/issues/7121#change-33763 Author: mjones (Morgan Jones) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: Target version: next minor =begin I was playing with Ruby tonight and thought up an interesting idea to make (({require})) a bit better, so you can load multiple files sequentially using one method call. Currently, (({require})) supports one argument, and throws a (({TypeError})) if you pass an array: irb(main):001:0> require %w(json yaml) TypeError: can't convert Array into String However, there's a way to patch Kernel that makes it respond to multiple objects passed in an (({Array})). module Kernel @@require = method :require def require *args args.flatten! args.collect! do |a| raise ArgumentError.new "arguments to `require' must be strings or symbols" unless a.is_a?(String) || a.is_a?(Symbol) @@require.call a.to_s end args.length == 1 ? args.first : args end end The new behavior doesn't actually require the modification of any code that calls (({require})) (pretty much anything, really), and new code can take advantage of the new functionality instantly. irb> require %w(json yaml) => [true, false] irb> require :pp => false irb> require 'rails' => true irb> require %w(json yaml), :pp, 'rails' => [true, false, false, true] =end Thanks for considering this. -- http://bugs.ruby-lang.org/