전체 글
-
[Week 1] Part 1: Ruby FoundationsaA 2022. 9. 12. 06:48
● Primitive Data Types ○ Booleans ○ Integers ○ Floats # 소수점 을 포함하는 숫자 ○ String Manipulation # string 삽입 #{} 사용, 인덱스[]를 사용하여 extract substring ..etc ○ Debugging Reading the stack trace Using debuggers correctly Intro to scientific method ● Methods, Iteration, Input/Output, Code Style ○ ArrayDRY # Don't Repeat Yourself ○ Blocks, Procs, and Lambdas # Blocks do / end 로 끝나거나, {} 으로 묶인 것. 다양한 변수를 가질 수..
-
Handling / Raising ExceptionsRuby 2022. 9. 11. 05:12
def format_name(first, last) if !(first.instance_of?(String) && last.instance_of?(String)) raise "arguments must be strings" end first.capitalize + " " + last.capitalize end first_name = 42 last_name = true begin puts format_name(first_name, last_name) rescue # do stuff to rescue the "arguments must be strings" exception... puts "there was an exception :(" end there was an exception :( raise는 예외..
-
Raising ExceptionsRuby 2022. 9. 11. 05:02
# Raising Exceptions # def format_name(first, last) if !(first.instance_of?(String) && last.instance_of?(String)) raise "arguments must be strings" # custom error message 를 만들고 에러가 뜬 순간 method는 종료된다. raise: this is how we can make exceptions manually. end first.capitalize + " " + last.capitalize end p format_name("grace", "hopper") p format_name(42, true) raise를 사용하여 오류(예외)를 어떻게 보여주는지 설정 할 수 있다.
-
Handling ExceptionsRuby 2022. 9. 11. 03:55
# handling Exceptions # num = 0 begin # error 가 뜨는 구간이 지정하고 exception을 만나기까지 실행 > exception에 도달되면 즉시 jump to rescue 된다. puts "dividing 10 by #{num}" ans = 10 / num puts "the answer is #{ans}" rescue # error가 떳을 때 대처되는 handling 방식 puts "There was an error with that division." end puts "--------" puts "finished" dividing 10 by 0 There was an error with that division. -------- finished num = 5 begi..
-
[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"]