Module: Enumerable
- Defined in:
- lib/enum_it_out.rb
Instance Method Summary collapse
Instance Method Details
#hash_it_out ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/enum_it_out.rb', line 15 def hash_it_out #changes an array to a hash raise ArgumentError.new("Array must have an even number of values") unless self.length % 2 == 0 new_hash = {} self.flatten self.each_with_index do |x, i| if i % 2 == 0 if x.is_a? String x.delete! ":" x = x.to_sym end new_hash[x] = self[i+1] end end return new_hash end |
#p_it_out ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/enum_it_out.rb', line 2 def p_it_out if self.is_a? Hash self.each do |k, v| print "#{k}: " p "#{v}" end else self.each do |x| p x end end end |