#Ruby problem on practice midterm possible solution.
module Enumerable
	def each_in_length_range(startRange, endRange)
		 self.each { |a| 
			if a.length >= startRange && a.length <= endRange
				yield a
			end
		 }
	end
end

myArray = ["one", "two", "three", "four", 
            "five", "six", "seven", "eight",
             "nine", "ten", "eleven", "twelve",
             "thirteen", "fourteen", "fifteen"]
myArray.each_in_length_range(5,6) { |a|
  print a
  print "\n"
}

class MyClass
	def method_missing (name, *args)
		print "I dont have method #{name}\n"
	end
	
	def addThisMethod (name) 
		MyClass.class_eval {
			eval("def #{name}; print 'Im from #{name}\n'; end")
		}
	end
  
  def addTwoMethods(name)
    MyClass.class_eval {
      eval("
			def #{name}
        print 'Im from class_eval\n'
      end")
		}
		
		MyClass.instance_eval {
			eval("
      def #{name}
				print 'Im from from instance_eval\n'
			end")
		}
  end
end


myInstance = MyClass.new


#Fires  method_missing
myInstance.there

#Adds method there
myInstance.addThisMethod 'there'

#Calls method there
myInstance.there

#Adds both a class and an instance method "addMe"
myInstance.addTwoMethods "addMe"

#Instance method (from class_eval)
myInstance.addMe

#Class method (from instance_eval)
MyClass.addMe