coding for food
-
[Ruby]coding for food 2022. 9. 4. 04:22
class IceCreamShop attr_accessor :flavors #setter/getter mathod와 instance variable 역할 def initialize #초기 셋팅을 해줌 @flavors = [] end def add_flavor (icecream) @flavors ["Vanilla", "Chocolate", "Strawberry"] the_freeze.remove_flavor "Vanilla" the_freeze.flavors # => ["Chocolate", "Strawberry"]
-
[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