Created
November 19, 2011 03:00
-
-
Save pasberth/1378365 to your computer and use it in GitHub Desktop.
requireでオプションを指定できるといいなーと思った
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $options = { you: nil }.merge $options || {} | |
| if $options[:you] | |
| puts "hello #{$options[:you]}" | |
| else | |
| puts "hello guest" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # $ 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