예상 리딩 타임: 30min ~ 1hour
아래의 다큐멘테이션은, 간단한 유저모델, 그리고 간단한 글을 남길 수 있도록 API 설계와 함께 구성 되어 있습니다.
major types: Integer, Float, Array, String, Hash, Boolean
integer
a = 5; b = 6
#number: integer, float > +,-,*,%,/
float
a = 1.23451;
Array
a = Array.new; #or
a = []
a << 5
a << "6"
a << [9]
puts "#{a}"
-> [5,"6", [9]]
String
str = "Hi! This is good!"
Hash
value2 = [5]
hash = {
key1: "value1",
key2: value2,
}
key1 <-- symbol
#old style
hash = {
:key1 => "value1",
:key2 => value2
}
#1.
puts hash[:key1]
#-> "value1"
#2.
value2 = 3
hash[:key2] ?
-> [5]
# -> 레일즈에서는 이미 지나갔습니다..🏃♀️
Boolean - true/false
a = true
if a
puts "true 입니다"
end
b = false
unless b
puts "false 입니다"
end
Terms: method, module, class
class : 말로 설명한다면.. 하나의 기초구조! 라고 할 수 있습니다. 이 기초구조에는 여러가지 method를 내포하게 할 수 있고, 또 여러가지 state를 넣을 수도 있습니다.
class SomeClass
def initialize
@some_data = 'initial value'
end
def insert_this_value(val)
@some_data = val
end
def get_data
return @some_data
end
end
# a = SomeClass.new
# a.get_data # -> initial value
# a.insert_this_value('hello')
# a.get_data # -> hello
method - 자바스크립트에서 함수랑 같습니다. RoR에서는 method라는 말을 사용합니다.
#starts with def
#return
#and end
def add(a, b)
return a + b
end
def subtract(a,b)
return a - b
end
def how_to_use
added = add(1,2)
puts "result: #{added}"
subtracted = subtract(2,1)
puts "result: #{subtracted}"
end
module
module FirstModule
module SubModule
class SomeClass
def initialize
@some_var = "init"
end
def update_var(str)
@some_var = str
end
def get_var
return @some_var
end
end
end
end
##---
some = FirstModule::SubModule::SomeClass.new
some.get_var
#init
some.update_var("new value")
some.get_var
#new value
auto load path
module Tutorial2
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1
config.autoload_paths << "#{Rails.root}/lib"
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
end
end
리액트에선 package.json과 같은 역할을 합니다. 이곳에 필요한 라이브러리를 불러오고, bundle 커맨드를 리눅스에서 입력하여 설치 합니다. bundle을 하기 위해선 bundler가 설치 되어 있어야 합니다. 설치 되어 있지 않은 경우 지시사항을 따라서 설치 하면 됩니다.
초반에는 버저닝이라는게 매우 까다롭게 다가옵니다. 처음에 루비와 레일즈에 초점을 두시고, 익숙해지실 즈음, 버저닝의 세계에 빠져보시길 권장합니다.