44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/enum_it_out.rb', line 44
def hash_it_out
raise ArgumentError.new("String must have an even number of values") unless self.split.length % 2 == 0
new_hash = {}
string = self
string.delete! ":"
string.delete! ","
while string.include? (" ")
key = string.slice!(/\w*\s/)
if string.include? (" ")
value = string.slice!(/\w*\s/)
else
value = string.slice!(/\w*/)
end
value.delete!(" ")
key = key.delete!(" ").to_sym
new_hash[key] = value
end
return new_hash
end
|