분류 전체보기
-
[Ruby] instance variablescoding for food 2022. 9. 3. 04:02
class User def username=(value) @username = value end def username @username end end p username = "coolgirl" p username setter, getter methods, instance variable(@username)의 모든 역할을 하는 것 = attr_accessor class User attr_accessor :username end
-
[Ruby] class 정리coding for food 2022. 9. 2. 10:57
object은 데이터 타입의 structure 이다. class Dog # has a tail # has a name # has a breed # can bark # can drink water from bowl end fido = Dog.new #=> fido는 Dog class의 instance(사례)이다. Class: 커스텀한 데이터 structure를 위한 템플랫이다. Object: An instance of a class. This would be Fido himself. Fido is a dog. Or, more specifically, fido is a Dog. "fire extinguisher".class #=> String “fire extinguisher”는 instance of the..
-
[git] Basicscoding for food 2022. 8. 31. 23:49
Version control is a tool developers use to keep changes across multiple software versions organized. git init : Creates an empty git repository. git status : Tells you whether you have untracked or modified files not yet in the staging area. git add : Adds a file to the staging area. You can add multiple files by listing them (separated by spaces) or add all the files at once by using git add ...
-
[Ruby] class //Inheritancecoding for food 2022. 8. 26. 08:43
class Chef # superclass def make_chicken puts "The chef makes chicken" end def make_salad puts "The chef makes salad" end def make_special_dish puts "The chef makes bbq ribs" end end class ItalianChef < Chef # subclass def make_special_dish puts "The chef makes eggplant parm" end end chef = Chef.new() chef.make_special_dish italian_chef = ItalianChef.new() italian_chef.make_special_dish
-
[Ruby] class를 이용한 building a quizcoding for food 2022. 8. 26. 03:59
class Question attr_accessor :prompt, :answer def initialize(prompt, answer) @prompt = prompt @answer = answer end end p1 = "what color are banana?\n(a)pink\n(b)yellow\n(c)red" p2 = "what color are apple?\n(a)blue\n(b)purple\n(c)red" questions = [ Question.new(p1, "b"), Question.new(p2, "c") ] def run_test(questions) answer = "" score = 0 for question in questions puts question.prompt answer = g..
-
[Ruby] object method // class // instance variablecoding for food 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
-
[Ruby] Ruby class // initialized methodcoding for food 2022. 8. 26. 02:14
class Book #created my own data type and a template for what a book is attr_accessor :title, :author, :pages end book1 = Book.new() #creating book object book1.title = "Harry Potter" book1.author = "JK Rowling" book1.pages = 400 puts book1.title 여러번 쓰는 것을 initialized method를 이용해서 간결하게 쓸 수 있다. class Book attr_accessor :title, :author, :pages def initialize(title, author, pages) @title = title @au..
-
[Ruby] switch 역할을 할 때,,coding for food 2022. 8. 25. 12:40
secret_word = "kitty" guess = "" guess_count = 0 guess_limit = 3 out_of_guesses = false while guess != secret_word && !out_of_guesses if guess_count < guess_limit puts "enter guess: " guess = gets.chomp() guess_count += 1 else out_of_guesses = true end end if out_of_guesses puts "you lose" else puts "you won!" end