So, I'm new to ruby and very curious about it. I'm comming from python. in python I would do this to see if something was present in a dictionary.
dictionary = dict()
dictionary['key'] = 5
def inDictionary(key):
if key in dictionary:
execute code
else:
other code
Rather simple for me, in ruby on the other hand how would I do this? i've been trying stuff like
dictionary = Hash.new
dictionary['key'] = 5
def isDictionary(key)
if dictionary.has_key?(key)
puts 'has key'
end
end
I get the error, isDictionary undefined local variable or method "dictionary". What am I doing wrong, and thanks in advance.