Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created November 19, 2011 03:00
Show Gist options
  • Select an option

  • Save pasberth/1378365 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1378365 to your computer and use it in GitHub Desktop.
requireでオプションを指定できるといいなーと思った
$options = { you: nil }.merge $options || {}
if $options[:you]
puts "hello #{$options[:you]}"
else
puts "hello guest"
end
# $ ruby require_options.rb # => hello pasberth
# $ ruby hello.rb # => hello guest
alias require_options_original_require require
def require path, options={}
$options = options
require_options_original_require path
ensure
$options = nil
end
require "./hello", you: 'pasberth'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment