Skip to content

Instantly share code, notes, and snippets.

@adhown
Created November 27, 2012 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adhown/4151926 to your computer and use it in GitHub Desktop.
Save adhown/4151926 to your computer and use it in GitHub Desktop.
Learning ruby basic
require 'yaml'
bot_data = {
:presubs => [
["dont", "dont"],
["youre", "you're"],
["love", "like"]
],
:responses => {
:default => [
"I don't understand.",
"what?",
"Huhhh bete?"
],
:greeting => ["Hi. I'm [name]. Want to chat?"],
:farewell => ["Good bye!"]
'hello' => [
"How's it going?",
"How do you do?"
],
'i like *' => [
"Why do you like *?",
"Wow I like * too!"
]
}
}
#Menampilkan struktur user dengan yaml
#
puts bot_data.to_yaml
#Write the yaml data to file
f = File.open(ARGV.first || 'bot_data', "w")
f.puts bot_data.to_yaml
f.close
@Pysis868
Copy link

> ruby bot_data_to_yaml.rb
bot_data_to_yaml.rb:17: syntax error, unexpected tSTRING_BEG, expecting '}'
                'hello' => [
                 ^
bot_data_to_yaml.rb:17: syntax error, unexpected =>, expecting end-of-input
                'hello' => [
                          ^
> rubocop bot_data_to_yaml.rb
Inspecting 1 file
E

Offenses:

bot_data_to_yaml.rb:17:17: E: unexpected token tSTRING
(Using Ruby 2.0 parser; configure using TargetRubyVersion parameter, under AllCops)
                'hello' => [
                ^^^^^^^
bot_data_to_yaml.rb:20:18: E: unexpected token tCOMMA
(Using Ruby 2.0 parser; configure using TargetRubyVersion parameter, under AllCops)
                ],
                 ^
bot_data_to_yaml.rb:25:9: E: unexpected token tRCURLY
(Using Ruby 2.0 parser; configure using TargetRubyVersion parameter, under AllCops)
        }
        ^

1 file inspected, 3 offenses detected
  • Added comma at the end of line 16.
> ruby bot_data_to_yaml.rb

---
:presubs:
- - dont
  - dont
- - youre
  - you're
- - love
  - like
:responses:
  :default:
  - I don't understand.
  - what?
  - Huhhh bete?
  :greeting:
  - Hi. I'm [name]. Want to chat?
  :farewell:
  - Good bye!
  hello:
  - How's it going?
  - How do you do?
  i like *:
  - Why do you like *?
  - Wow I like * too!

Updated version here: GitHub Gist - Pysis868/bot_data_to_yaml.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment