Ruby - Methods, Blocks and Sorting - Little code correction


#1


https://www.codecademy.com/pt-BR/courses/ruby-beginner-pt-BR-qo3n9/0/1?curriculum_id=535951905d81961e16000001

Well, I'm an beginner with ruby and here have seen my first experience with this language, and I had like so much it. BTW, my report don't require much attention, it's simply a little bug that I have found at the following code of the exercise related to methods.

At the incorrect code, I could identified that the result shown when the parameter "n" is not a Interger it's correctly as defined in unless method, but also are shown the result saying that the number is prime, not breaking the program. Sorry if I cannot make me understand as fine, but I hope this help to make yet most good the class :slight_smile:

# Incorrect Code
def prime(n)
  puts "It is not a Interger." unless n.is_a? Integer
    is_prime = true
    for i in 2..n-1
      if n % i == 0
        is_prime = false
      end
    end
    if is_prime
      puts "#{n} is prime!"
    else
      puts "#{n} is not prime."
    end
end
#End incorrect code

# Correctly code
def prime(n)
  unless n.is_a? Integer
    puts "It is not a Interger."
  else
    is_prime = true
    for i in 2..n-1
      if n % i == 0
        is_prime = false
      end
    end
    
    if is_prime
      puts "#{n} is prime!"
    else
      puts "#{n} is not prime."
    end
  end
end

# End Correctly code


#2

Thank you for reporting the problem, we recognise this is a bug, however as it does not prevent users from passing the lesson and this is one of the older courses it is unlikely this bug will be fixed. Thank you for taking the time to inform us though, we would like everything to be fixed just as much as you would! :smiley:


#3

I understand....

Anyway, keeps for learning purposes :slight_smile:

Thanks for the support, great course