Skip to content

Instantly share code, notes, and snippets.

@tomoyamkung
Created August 8, 2012 06:01
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/3292590 to your computer and use it in GitHub Desktop.
Save tomoyamkung/3292590 to your computer and use it in GitHub Desktop.
[Ruby]YAML に定義してある配列に追加するスニペット
#! 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