Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/enum_it_out.rb

Instance Method Summary collapse

Instance Method Details

#arr_itObject



36
37
38
39
40
41
42
# File 'lib/enum_it_out.rb', line 36

def arr_it
  #changes string into array of words separated by spaces
  #removes commas
  self.delete! ","
  new_array = self.split
  return new_array
end

#hash_it_outObject

Raises:

  • (ArgumentError)


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