Created
March 15, 2010 01:16
-
-
Save tomohiro/332399 to your computer and use it in GitHub Desktop.
文字列でメソッド呼び出しの使用例
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
#!/usr/bin/env ruby | |
require 'optparse' | |
require 'ostruct' | |
require 'yaml' | |
mode = 'production' | |
ARGV.options do |o| | |
o.on('-d', "--development") { |v| mode = 'development' } | |
o.parse! | |
end | |
config = OpenStruct.new(File.open('config.yaml') { |f| YAML.load(f) }) | |
server = config.method(mode).call | |
### case で書いた場合 | |
case mode | |
when 'development' | |
server = config.development | |
else | |
server = config.production | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment