coding for food

[Ruby] object method // class // instance variable

silveryen 2022. 8. 26. 03:02
class Student 
    attr_accessor :name, :major, :gpa
    def initialize(name, major, gpa)
        @name = name
        @major = major
        @gpa = gpa
    end

    def has_honors
        if @gpa >= 3.5   #class 안에서 모두 사용할 수 있는 instance variable (@gpa)
            return true
        end
            return false
    end
end

Student1 = Student.new("Jiji", "Art", 2.6)
Student2 = Student.new("Kim,", "Business", 3.6)

puts Student2.has_honors