Created
July 19, 2012 05:21
-
-
Save tomoyamkung/3140934 to your computer and use it in GitHub Desktop.
Ruby で YAML を読み込むコードスニペット
This file contains 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 スクリプトの拡張子を "yaml" にした YAML が、スクリプトと同じディレクトリに存在する場合の例 | |
## - Ruby スクリプト:hoge.rb | |
## - YAML:hoge.yaml | |
#! ruby | |
#-*- encoding: utf-8 -*- | |
require 'yaml' | |
class Hoge | |
def initialize(exec_file) | |
@yaml = YAML.load_file(get_yaml(exec_file)) | |
end | |
def get_yaml(exec_file) | |
return exec_file.sub("rb", "yaml") | |
end | |
end | |
if __FILE__ == $0 | |
obj = Hoge.new(__FILE__) | |
obj.print | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment