I have an example YAML file:
---
- foo:
- 1
- 2
- 3
- bar: test123
- lol: test456| def replace_line_in_file(old,new,file) | |
| File.open(file) do |f| | |
| File.open(file + ".new", "w") do |f2| | |
| f.each_line do |line| | |
| f2.puts line.gsub(old, new) | |
| end | |
| end | |
| end | |
| File.rename(file + ".new", file) | |
| end |
| class Hash | |
| def map_value | |
| each_pair.with_object({}) { |(key, value), result| result[key] = yield value } | |
| end | |
| def map_key | |
| each_pair.with_object({}) { |(key, value), result| result[yield key] = value } | |
| end | |
| def map_pair(&blk) |
| def evaluate(expression) | |
| stack = [] | |
| expression.split.each do |word| | |
| case word | |
| when "+" | |
| stack << (stack.pop + stack.pop) | |
| when "-" | |
| arg1 = stack.pop | |
| arg2 = stack.pop |
| #include <unistd.h> | |
| #include <stdio.h> | |
| #include <time.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| char *foo2 () | |
| { | |
| return "FOO"; | |
| } |
I have an example YAML file:
---
- foo:
- 1
- 2
- 3
- bar: test123
- lol: test456