Ad
Code
Diff
  • class Functionator
      attr_reader :allowed_methods, :callers, :next_caller
    
      def initialize(s)
        @allowed_methods = s.split
        init_caller
      end
    
      def method_missing(method, *args)
        method = method.to_s
        raise NoMethodError, 'Not exists' unless @allowed_methods.include?(method)
        raise NoMethodError, 'Wrong order' unless @next_caller == method
        wait_next_caller
        self
      end
    
      private
    
      def wait_next_caller
        @next_caller = @callers.next
      rescue StopIteration
        init_caller
      end
    
      def init_caller
        @callers = @allowed_methods.each
        @next_caller = @callers.next
      end
    end
    
    def functionator(methods)
      Functionator.new methods
    end
    • class Functionator
    • attr_reader :allowed_methods, :callers, :next_caller
    • def initialize(s)
    • s.split(' ').each { | i | define_singleton_method :"#{i}" do Functionator.new(s.split(' ')[1..-1].join(' ')) end }
    • @allowed_methods = s.split
    • init_caller
    • end
    • def method_missing(method, *args)
    • method = method.to_s
    • raise NoMethodError, 'Not exists' unless @allowed_methods.include?(method)
    • raise NoMethodError, 'Wrong order' unless @next_caller == method
    • wait_next_caller
    • self
    • end
    • private
    • def wait_next_caller
    • @next_caller = @callers.next
    • rescue StopIteration
    • init_caller
    • end
    • def init_caller
    • @callers = @allowed_methods.each
    • @next_caller = @callers.next
    • end
    • end
    • def functionator(string)
    • Functionator.new(string)
    • def functionator(methods)
    • Functionator.new methods
    • end
Code
Diff
  • def array_of_two(n)
      [n.to_int, n.to_int]
    end
    
    • def array_of_two(n)
    • raise 'n is not a number' unless n.is_a?(Numeric) # comment to fail test case
    • [n, n]
    • [n.to_int, n.to_int]
    • end