I'm trying to compare user input to values in my hash.
For example, if I ran "e".scrabble() in IRB, it would return the value for "e" in my hash.
I figured out how to identify if it's in my hash and if it's equal to one of the keys in the hash.
class String
define_method(:scrabble) do
value_for_letters = {
"A"=> 9,"B" => 2,"C" => 2,"D" => 4,"E" => 12,"F" => 2,
"G" => 3, "H" => 2, "I" => 9,"J" => 1, "K" => 1,
"L" => 4,"M" => 2,"N" => 6,"O" => 8,"P" => 2,"Q" => 1,
"R" => 6,"S" => 4,"T" => 6,"U" => 4,"V" => 2,"W" => 2,
"X" => 1,"Y" => 2,"Z" => 1
}
value_for_letters.keys().==(self.capitalize())
"true"
end
end
define_methodrather than simplydef scrabble...and that you invoked the methodString#==in the formal way (.==(...)), rather than using the "syntactic sugar"keys() == self.capitalize(the extra parens are not necessary, btw). I suspect that's what you are being taught in your early days of learning Ruby, which is a very good thing! You will learn the conventional methods soon enough.