Skip to content

Instantly share code, notes, and snippets.

@tomohiro
Created March 15, 2010 01:16
Show Gist options
  • Save tomohiro/332399 to your computer and use it in GitHub Desktop.
Save tomohiro/332399 to your computer and use it in GitHub Desktop.
文字列でメソッド呼び出しの使用例
#!/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