Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from kalmanh/method_missing_way

Removing unneccesary methods
  • Loading branch information...
commit 94a3ad88b602403592a01f85e2ef8e6324b58aca 2 parents f864a25 + 9ac4bec
@SatishTalim authored
Showing with 12 additions and 17 deletions.
  1. +12 −17 chess_opener.rb
View
29 chess_opener.rb
@@ -3,27 +3,22 @@ def initialize
@data = {}
load_data
end
-
+
def self.load(filename)
dsl = new
dsl.instance_eval(File.read(filename))
end
-
- def h4
- puts "=========="
- puts @data.assoc("h4")
- puts "=========="
- end
-
- def a3
- puts "=========="
- puts @data.assoc("a3")
- puts "=========="
- end
def method_missing(method_name, *args, &block)
- msg = "You tried to call the method #{method_name}. There is no such method."
- raise msg
+ data_array = @data.send(:[], method_name.to_s)
+ if data_array
+ puts "=========="
+ puts @data[method_name.to_s]
+ puts "=========="
+ else
+ msg = "You tried to call the method #{method_name}. There is no such method."
+ raise msg
+ end
end
private
@@ -37,5 +32,5 @@ def load_data
"Borg Gambit continues 1.h4 g5.",
"Symmetric Variation continues 1.h4 h5"]}
end
-
-end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.