Created
August 8, 2012 06:01
-
-
Save tomoyamkung/3292590 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 | |
#-*- encoding: utf-8 -*- | |
require 'yaml' | |
class AddArray | |
def initialize(path) | |
@path = path | |
end | |
def execute(str) | |
config = YAML.load_file(@path) | |
config['words'] << str | |
File.open(@path, 'w'){|yaml| | |
YAML.dump(config, yaml) | |
} | |
end | |
end | |
if __FILE__ == $0 | |
obj = AddArray.new('./array.yaml') | |
obj.execute(ARGV[0]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment