Skip to content

Instantly share code, notes, and snippets.

@tomoyamkung
Created July 19, 2012 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoyamkung/3140934 to your computer and use it in GitHub Desktop.
Save tomoyamkung/3140934 to your computer and use it in GitHub Desktop.
Ruby で YAML を読み込むコードスニペット
## 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