ã¯ããã«
ããã¯Rubyèšèªã«ã€ããŠåŠç¿ããããšã®èšé²ã§ãã
Rubyã£ãŠã©ãããååšïŒ
- ãªããžã§ã¯ãæåèšèª(ãã¹ãŠããªããžã§ã¯ãã§ã§ããŠãã)
- ã¹ã¯ãªããèšèª(ã³ã³ãã€ã«æãã§å®è¡ã§ãã)
Rubyãã¡ã€ã«ã®å®è¡
ruby ãã¡ã€ã«å.rb
å€éšãã¡ã€ã«ã®èªã¿èŸŒã¿
requre "ã©ã€ãã©ãªå"
# èªåã§äœã£ããã¡ã€ã«ãèªã¿èŸŒã
require "./ãã¡ã€ã«å" # æ¡åŒµåã.rbãã¯çç¥å¯
# Ex. åããã£ã¬ã¯ããªäžã«ãããsample.rbããšãããã¡ã€ã«ãèªã¿èŸŒãå Žå
require "./sample"
ã³ã¡ã³ãã¢ãŠã
# 1è¡ã®ã³ã¡ã³ãã¢ãŠã
=begin
è€æ°è¡ã®ã³ã¡ã³ãã¢ãŠãã¯ããã§ãã
ããã«æžããããšã¯å®è¡ãããŸããã
=end
# ããã§ã
# ããã§ã
ããžãã¯ã³ã¡ã³ã
ããã°ã©ã ã®å é è¡ã«å ¥ãããããåªæã
# frozen_string_literal: true
ããã«ãã³ã¡ã³ãã¢ãŠãã®ããã«èŠããŸããâŠ
str1 = "hello"
str2 = "hello"
p str1.frozen? #=> false
p str1.object_id == str2.object_id #=> false
# frozen_string_literal: true
str1 = "hello"
str2 = "hello"
p str1.frozen? #=> true
p str1.object_id == str2.object_id #=> true
ãã®ããã«åºåã«å·®ãåºãŸãã
Rubyã§ã¯ãªããžã§ã¯ãã«å¯ŸããŠãŠããŒã¯ãªæŽæ°(ãªããžã§ã¯ãID)ãå²ãåœãŠãããã®ã§ããã# frozen_string_literal: true
ãèšè¿°ããŠãããšãããã©ã«ãã§ãæåã®å
容ãåããªãããªããžã§ã¯ãIDãåãã«ããŸãããšããèšå®ãåããŸãã
ãªããžã§ã¯ãã«å¯ŸããŠ.object_id
ã¡ãœããã䜿ããšIDã®äžèº«ã確èªã§ããŸãã
irb (ã€ã³ã¿ã©ã¯ãã£ãRuby)
ã³ã³ãœãŒã«ã«irb
ã³ãã³ããå
¥åããŠEnter
irb
irb(main):001> # ããã«Rubyã®ã³ãŒããèšè¿°ãã
ç°¡åãªRubyã®ããã°ã©ã ãè©Šãã®ã«äŸ¿å©ã§ããããã§è¡ã£ãæäœã¯ç¹ã«ä¿åãããŸããã
exit
ã§çµäºã§ããå
ã®ã³ã³ãœãŒã«ã«æ»ããŸãã
irb(main):001> exit
ããã³ããã®ç¢å°ãã·ã³ãã«ã«ãããªãã·ã§ã³
irb --simple-prompt
>> # èŠããããŠäŸ¿å©
å ¥å / åºå
- å
¥åã«äœ¿ãã³ãã³ã:
gets
- åºåã«äœ¿ãã³ãã³ã:
p
,print
,puts
å ¥å: gets
input = gets # inputãšããå€æ°ã«å
¥åå€ãæ ŒçŽ
gets
: äžè¡ãèªã¿èŸŒãã§ãèªã¿èŸŒã¿æåæã«ã¯ãã®æååãè¿ããŸãã
ã€ãŸããè€æ°è¡ãèªã¿èŸŒã¿ããå Žåã¯getsã³ãã³ããè€æ°åå®è¡ããåŠçãæžããããgetsã§ååŸããå€ãæŽæ°ã«å€ãããæã¯to_i
ã¡ãœããã䜿ããªã©ã®å·¥å€«ãå¿
èŠã§ãã
æ¹è¡æåãé€å»ããchomp
ã¡ãœãããšçµã¿åãããŠgets.chomp
ãšããã®ã¯ããããæã§ãã
åºå: p, print, puts
p
: æååãããã§ãªãããèŠåãããã圢ã§åºåããŸãã
# åæ
å ±ãäžç·ã«åºå
p "Hello" #=> "Hello"
p 1 #=> 1
print
: æ«å°Ÿã«æ¹è¡æåãå
¥ããã«åºåããŸãã
print "ããã«ã¡ã¯"
print 21
print "äžçŽå°å¹Ž"
#=> ããã«ã¡ã¯21äžçŽå°å¹Ž
puts
: åŒæ°ãšæ¹è¡ãé çªã«åºåããŸããåŒæ°ãªãã®å Žåã¯æ¹è¡ã®ã¿ãåºåããŸãã
[ãµã³ãã«ã³ãŒã]
puts 1
puts "H"
puts "E"
puts "L"
puts "L"
puts "O"
puts # åŒæ°ãªã
puts ["æ¯æ¥ãããã€", "倧äºã§ã"] # åŒæ°ãé
å
[ãµã³ãã«ã¢ãŠãããã]
1
H
E
L
L
O
æ¯æ¥ãããã€
倧äºã§ã
ã¡ãœããå®çŸ©ãšå®è¡
ã¡ãœããå®çŸ©
def ã¡ãœããå(åŒæ°)
åŠç
end
ãµã³ãã«ã³ãŒã
def hello # åŒæ°ã®ãªãã¡ãœãããå®çŸ©
puts "Hello"
end
hello # åŒæ°ãªãã§ã¡ãœããå®è¡
#=> Hello
def greeting(name)
puts "Hello, #{name}."
end
greeting("Mike") # åŒæ°ãæž¡ããŠã¡ãœããå®è¡
#=> Hello, Mike.
åŒå±é
#{å€æ°åãåŒ}
: ããã«ã¯ã©ãŒãã§å²ãã æååã®äžã§ãåŒã®å®è¡ãå€æ°ã®å€ãæååã«åã蟌ã圢ã§è¡šç€ºã§ããŸãã
name = "Nick"
puts "My name is #{name}."
#=> My name is Nick.
puts "#{1 + 2}"
#=> 3
ãªããžã§ã¯ãã®ã¯ã©ã¹(åã®ãããªãã®)ã調ã¹ã
.class
: ãªããžã§ã¯ãã®ã¯ã©ã¹åãè¿ããŸãã
p 123.class #=> Integer
p 0.1.class #=> Float
p "sample".class #=> String
p nil.class #=> NilClass
p true.class #=> TrueClass
.is_a?(ã¯ã©ã¹å)
: ãªããžã§ã¯ãããåŒæ°ã§äžããããã¯ã©ã¹ãŸãã¯ãµãã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ã§ããããå€å®ããããŒãªã¢ã³å€ãè¿ããŸãã
p "text".is_a?(String) #=> true
p 0.is_a?(String) #=> false
æ¡ä»¶åå²
if
~ elsif
~ else
~ end
: Rubyã¯elsifãšããè¡šèšãªã®ã§æ³šæã
if æ¡ä»¶åŒA
æ¡ä»¶åŒAãtrueã®æã«å®è¡ããåŠç
elsif æ¡ä»¶åŒB
æ¡ä»¶åŒBãtrueã®æã«å®è¡ããåŠç
else
ãããŸã§ã®æ¡ä»¶åŒãfalseã®æã«å®è¡ããåŠç
end
ç¹°ãè¿ã
each
æ: é
åã«ãã䜿ããŸããé
åã®èŠçŽ ã1ã€ãã€åãåºããåãåºããèŠçŽ ã«å¯ŸããŠã®åŠçãæžããŸãã
[ãµã³ãã«ã³ãŒã]
strings = ["ãªã©", "ç¡é§"]
strings.each do |string|
puts string * 10
end
[ãµã³ãã«ã¢ãŠãããã]
ãªã©ãªã©ãªã©ãªã©ãªã©ãªã©ãªã©ãªã©ãªã©ãªã©
ç¡é§ç¡é§ç¡é§ç¡é§ç¡é§ç¡é§ç¡é§ç¡é§ç¡é§ç¡é§
ããã·ã¥ã察象ã«ããeachæ
[ãµã³ãã«ã³ãŒã]
hsh = { ruby: "ã«ããŒ", perl: "ããŒã«", crystal: "ã¯ãªã¹ã¿ã«" }
hsh.each do |key, value|
puts "ããŒ: #{key}, ããªã¥ãŒ: #{value}"
end
[ãµã³ãã«ã¢ãŠãããã]
ããŒ: ruby, ããªã¥ãŒ: ã«ããŒ
ããŒ: perl, ããªã¥ãŒ: ããŒã«
ããŒ: crystal, ããªã¥ãŒ: ã¯ãªã¹ã¿ã«
while
æ: æ¡ä»¶ãtrueã§ããéã«ãŒãããŸããæ¡ä»¶ãfalseã«ãªãã°ã«ãŒããçµäºããŸãã
[ãµã³ãã«ã³ãŒã]
i = 18
good_night = 21
while i <= good_night
puts "ä»ã¯#{i}æã..."
i += 1
end
puts "ãããå¯ããïŒ"
[ãµã³ãã«ã¢ãŠãããã]
ä»ã¯18æã...
ä»ã¯19æã...
ä»ã¯20æã...
ä»ã¯21æã...
ãããå¯ããïŒ
until
æ: æ¡ä»¶ãfalseã®éãã«ãŒãããŸããwhileæã®éã®ãããªååšã§ãã
[ãµã³ãã«ã³ãŒã]
day = 1
num = 1
until day >= 31 # day ã31以äžã§ãããå€å®ããfalseã®éã«ãŒã
puts "#{day}æ¥ç®: ãç±³ã#{num}ç²ããã£ãã"
num *= 2
day += 1
end
[ãµã³ãã«ã¢ãŠãããã]
1æ¥ç®: ãç±³ã1ç²ããã£ãã
2æ¥ç®: ãç±³ã2ç²ããã£ãã
3æ¥ç®: ãç±³ã4ç²ããã£ãã
4æ¥ç®: ãç±³ã8ç²ããã£ãã
... (äžç¥) ...
28æ¥ç®: ãç±³ã134217728ç²ããã£ãã
29æ¥ç®: ãç±³ã268435456ç²ããã£ãã
30æ¥ç®: ãç±³ã536870912ç²ããã£ãã
é å
# 空ã®é
åãçæ
arr = []
# ãããããªãã®ãæ ŒçŽã§ããŠããŸã
sample_arr = [1, "hoge", { "name" => "Taro", "age" => 18 }]
é åãžã®èŠçŽ ã®æ ŒçŽãåãåºãæ¹æ³ããŸããé åã«çšæãããã¡ãœããã¯å€ãã®çš®é¡ããããŸãã奥ãæ·±ãã®ã§åå¥èšäºã«ãããã§ãã
ããã·ã¥
é£æ³é
åãšããããŸããããŒ
ãšå€
ã®çµã¿åããã§é¢é£ä»ããã§ãããšãããé
åãšç°ãªãç¹ã§ããé
åãã€ã³ããã¯ã¹ãšããæ·»åãããšã«å€ãåãåºããã®ã«å¯ŸããŠãããã·ã¥ã§ã¯user1
ãããšã«Michael
ãåãåºããããcountry1
ãããšã«æ¥æ¬
ãåãåºããããªã©ã人éãç解ãããã圢åŒã§å€ãæäœã§ããŸãã
hsh = { ããŒ1 => å€1, ããŒ2 => å€2 }
[ãµã³ãã«ã³ãŒã]
product = { "name" => "涌æã·ãŒã", "price" => 350 }
def price_half(item)
item["price"] /= 2
end
price_half(product) # åé¡ã¡ãœãããå®è¡
puts "ãªããšã#{product["name"]}ã#{product["price"]}åã§è²©å£²äžïŒ"
[ãµã³ãã«ã¢ãŠãããã]
ãªããšã涌æã·ãŒãã175åã§è²©å£²äžïŒ
ã·ã³ãã«
:symbol
ã®ãããªãå
é ã«ã³ãã³ãä»ããæååã®ããšã§ããèŠããã¯æååã§ãããå
éšã§ã¯ãŠããŒã¯ãªæŽæ°ãšããŠæ±ããããã·ã³ãã«ãšãããªããžã§ã¯ãããšããŠååšããŠããŸãã(Symbolã¯ã©ã¹)
ã·ã³ãã«ã䜿ãå Žé¢
ã·ã³ãã«ã¯äžåºŠäœããšäžå€ã§ãããæååãããã¡ã¢ãªå¹çãè¯ãããå€ã®æ¯èŒãé«éã§ãããã®æ§è³ªãããããã·ã¥ã®ããŒãšããŠã·ã³ãã«ã䜿ãããå Žé¢ãå€ãã§ãã
ããã·ã¥ã®ããŒã«ã·ã³ãã«ã䜿ãäŸ
sample_hash = { :Ruby => "Rails", :PHP => "Laravel" }
è¡šèšãéããåãæå³â
sample_hash = { Ruby: "Rails", PHP: "Laravel" }
[ãµã³ãã«ã³ãŒã]
shinsei_b_komachi = [
{ name: "ã«ããŒ", age: 16 },
{ name: "ããª", age: 17 },
{ name: "MEMã¡ã", age: 25 }
]
shinsei_b_komachi.each do |member|
if member[:age] >= 18
puts "#{member[:name]}ã¯æ人ã§ã"
else
puts "#{member[:name]}ã¯æªæ幎ã§ã"
end
end
[ãµã³ãã«ã¢ãŠãããã]
ã«ããŒã¯æªæ幎ã§ã
ããªã¯æªæ幎ã§ã
MEMã¡ãã¯æ人ã§ã
ã¯ã©ã¹ããŒã¹ã®ãªããžã§ã¯ãæå
ã¢ãã«æ³šç®ããŠçŸå®äžçãæããŠããã°ã©ã ã«èœãšã蟌ãããæ¹ãšããŠãªããžã§ã¯ãæåããã°ã©ãã³ã°(OOP: Object-Oriented Programming)ããããŸãã
ãã¢ãã®æ§è³ª(ã€ã³ã¹ã¿ã³ã¹å€æ°)ããšãã¢ãã®æäœ(ã¡ãœãã)ãããã¯ã©ã¹ããšããèšèšå³ã«å®çŸ©ããŠãã¯ã©ã¹ãããšã«ãã€ã³ã¹ã¿ã³ã¹ããçæããææ³ãã¯ã©ã¹ããŒã¹ã®ãªããžã§ã¯ãæåã§ãã
# ã¯ã©ã¹å®çŸ©
class ã¯ã©ã¹å
# attr_accessor[reader/writer] ã§ã²ãã¿ãŒãã»ãã¿ãŒã¡ãœããã楜ã«äœãã
def initialize # ã€ã³ã¹ã¿ã³ã¹çææã«åŒã°ããã¡ãœãã
倧äœã¯ããã§ã€ã³ã¹ã¿ã³ã¹å€æ°ãçšæãã
end
def äœããã®ã¡ãœãã
end
end
# ã€ã³ã¹ã¿ã³ã¹ãçæ
å€æ° = ã¯ã©ã¹å.new(åŒæ°)
[ãµã³ãã«ã³ãŒã]
class Bird
def initialize(name)
@name = name
end
def fly
puts "#{@name}ã¯ç©ºãžé£ã³ç«ã€"
end
def eat(food)
puts "#{@name}ã¯#{food.name}ã#{food.quantity}é£ã¹ã"
end
end
class Penguin < Bird
def fly
puts "#{@name}ã空ãžé£ã³ç«ã€ããšã¯å¶ããªãã£ã..."
end
end
class Food
attr_reader :name, :quantity
def initialize(name)
@name = name
@quantity = 0
end
def set_quantity(num)
@quantity = num.to_i
end
end
# å®è¡
crow = Bird.new("ã«ã©ã¹")
crow.fly
penguin = Penguin.new("ãã³ã®ã³")
penguin.fly
fish = Food.new("é")
fish.set_quantity(23)
penguin.eat(fish)
[ãµã³ãã«ã¢ãŠãããã]
ã«ã©ã¹ã¯ç©ºãžé£ã³ç«ã€
ãã³ã®ã³ã空ãžé£ã³ç«ã€ããšã¯å¶ããªãã£ã...
ãã³ã®ã³ã¯éã23é£ã¹ã
ãªããžã§ã¯ãæåãäžæã䜿ããããã«ãªããšã
- å®è¡æãç°¡æœã§äœãããŠãããããããããããªã
- ã³ãŒãã®ä¿å®æ§ã»æè»æ§ãäžãã
- åããããªãã®ã䜿ãåãã
- ããç®æãå€æŽããå Žåã«ããã®åœ±é¿ç¯å²ã1ã€ã®è²¬ä»»å ã«åãŸã
ãªã©ã®ã¡ãªããããããŸãã
çŸåšã¯é¢æ°åããã°ã©ãã³ã°ã®äººæ°ã䌞ã³ãŠããŸãããããã¯ãã£ãŠãããªããžã§ã¯ãæåãç¥ã£ãŠããã䜿ãããåæã§çŸå Žã¯åããŠãããããªã®ã§ãé 匵ã£ãŠäœ¿ãããªããããã«ãªãããã§ããé£ããâŠã
äŸå€åŠç
äŸå€(exception)ãšã¯ãåŠçã®å®è¡äžã«çºçãããšã©ãŒã®ããšã§ãã
äŸå€æã«åºãäŸå€å€å®ãããšã«ãé©åãªäŸå€åŠçãè¡ãããšã§ã·ã¹ãã åæ¢ãããŒã¿ç Žæãé²ããŸãããã
ãã®æåãªãã¬ããœãã¯Javaã®ãNullPointerExceptionããšããnullå€ã®åç
§åå€æ°ãåç
§ããããšããæã«åºãŠããäŸå€ããæ¥ãŠããŸãã
RubyãçšæããŠããäŸå€ã®ã¯ã©ã¹
- Exception
- StandardError: åºæ¬ã¯ãã®åãè£è¶³ãã
- ZeroDivisionError
- ArgumentError
- NoMethodError
ã»ã
- StandardError: åºæ¬ã¯ãã®åãè£è¶³ãã
begin
~ end
ã§äŸå€ãçºçããããªåŠçãå²ã¿ãrescue
ã§ãšã©ãŒãè£è¶³ããrescue
åŸã®éšåã«äŸå€åŠçãèšè¿°ããŸãã
begin # äŸå€ã®äºæããããbeginã§å²ã
äœããã®åŠç
rescue StandardError # äžèšåŠçã§StandardErrorãåãåºãããå Žåã«äŸå€åŠçãå®è¡
äŸå€åŠçãæžã
else
æ£åžžãªæã®åŠçãæžã
ensure
æ£åžžã§ããããšäŸå€ã§ããããšå®è¡ããåŠçãæžã
end
å€æ°ã«äŸå€ãªããžã§ã¯ããå²ãåœãŠãæ§æ
rescue
ã§äŸå€ãææããæã«ãå€æ°e
ã«æ ŒçŽããç¹æ®ãªæ§æããããŸãã
ãã°ãã°ãšã©ãŒã¡ãã»ãŒãžãåãåºãã®ã«äœ¿ãããŸãã
begin
# åŠç
rescue StandardError => e
puts "Error: #{e.message}"
end
raise çºçããããäŸå€ã®ã¯ã©ã¹
: æ瀺çã«ãšã©ãŒãåºãå Žåã«äœ¿ããŸãã
[ãµã³ãã«ã³ãŒã]
begin
puts 1 / 0
rescue StandardError => e
puts "Error: #{e.message}"
end
#=> Error: divided by 0
begin
raise ArgumentError.new("åŒæ°ãšã©ãŒã§ãã")
rescue StandardError => e
puts "Error: #{e.message}"
end
#=> Error: åŒæ°ãšã©ãŒã§ãã
gem: å€éšã©ã€ãã©ãª
Rubyã§ã¯ãgemãšãã圢åŒã§å€éšã©ã€ãã©ãªãæäŸãããŠãããèªåã§gemãäœã£ãŠæäŸããããšãã§ããŸãã
gemã®ã€ã³ã¹ããŒã«
gem install ã©ã€ãã©ãªå
ã€ã³ã¹ããŒã«ãããŠããgemã®äžèŠ§è¡šç€º
gem list
gemã®ã¢ã³ã€ã³ã¹ããŒã«
gem uninstall ã©ã€ãã©ãªå
Bundlerã§äŸåé¢ä¿ã解æ¶
Bundlerã¯è±èªã®bundle(æãã)ãç±æ¥ã®gemã®äŸåé¢ä¿ã管çããããŒã«ã§ãã
Bundlerèªèº«ãgemã§ãããäžåºŠBundlerãã€ã³ã¹ããŒã«ãããšããã®åŸã¯äž»ã«Bundlerã䜿ã£ãŠä»ã®gemãå°å
¥ããããã«ãªãã»ã©ã®äŸ¿å©ãªãã€ã§ãã
Bundlerã䜿ã£ãŠgemãã€ã³ã¹ããŒã«ããæé
ã¹ããã1. Gemfile
ãäœæãã
bundle init
ã䟿å©
cd ãããžã§ã¯ãã®ãã£ã¬ã¯ããª
bundle init
# äžèšã³ãã³ãã§GemfileãäœæãããŸãã
ã¹ããã2. Gemfileã«ã€ã³ã¹ããŒã«ãããgemã®ååãæåå(ããã«ã¯ã©ãŒããŸãã¯ã·ã³ã°ã«ã¯ã©ãŒãã§å²ãæžãæ¹)ã§èšè¿°ãã
# -- Gemfile --
source "https://rubygems.org" # ã€ã³ã¹ããŒã«å
ãæå®
gem "ã€ã³ã¹ããŒã«ãããgemã®åå" # ããŒãžã§ã³ãæå®ããªãå Žå
gem "ã€ã³ã¹ããŒã«ãããgemã®åå", "~> 4.2.0" # ããŒãžã§ã³ãæå®ããå Žå
ã¹ããã3. bundle install
ãå®è¡ãã
bundle install
# Gemfileã«èšèŒãããgemããBundlerãäžæ¬ã§ã€ã³ã¹ããŒã«ãã
# ãã®æãããŒãžã§ã³ã瀺ãGemfile.lockãçæããã
Bundlerã§gemãã¢ã³ã€ã³ã¹ããŒã«ããæé
ã¹ããã1. bundle exec gem uninstall
ãå®è¡ãã
bundle exec gem uninstall äžèŠãªgemã®åå
# ããŒãžã§ã³æå®ç
bundle exec gem uninstall äžèŠãªgemã®åå -v "ããŒãžã§ã³å"
ã¹ããã2. Gemfile
ãã該åœéšåãåé€ãã(æåã§åé€)
-- Gemfile --
# æåã§æ¶ãã°OK
ã¹ããã3. Gemfile.lock
ããåé€ãã(bundle update ãå®è¡)
bundle update
# ãŸã㯠bundle install ã§ãå¯
# Gemfile.lock ã®äžèº«ãæŽæ°ããã
ãããã°gem: Ruby/debug
ã®æŽ»çš
éåžžã«äŸ¿å©ãªãããã°çšã®gemã§ãã
gemã®ã€ã³ã¹ããŒã«ãå®è¡åŸã«ã
Rubyã³ãŒãå ã§äœ¿ã
ã³ãŒãã®å
é ã®æ¹ã«require "debug"
ã§èªã¿èŸŒã¿ãè¡ãããããã°ã³ã³ãœãŒã«ãèµ·åãããå Žæã«binding.b
ãä»èŸŒãã ãã§ãã
# Rubyãã¡ã€ã«
require "debug"
binding.b # ãã®ç®æã§ãããã°ã³ã³ãœãŒã«ãèµ·åãã
ãããã°ã³ã³ãœãŒã«ã§ã¯ãn
ã§æ¬¡ã®ã¹ãããã«é²ãã ããi
(info)ã§å€æ°äžèŠ§ã衚瀺ãããã§ããŸãã
éç解æããŒã«gem: RuboCop
ã®æŽ»çš
gemårubocop
: ã€ã³ã¹ããŒã«åŸã«ãéç解æããããã£ã¬ã¯ããªäžã§rubocop
ã³ãã³ãã䜿ããšè§£æçµæã衚瀺ãããŸãã
ããã©ã«ãã®èšå®ã¯ã¬ãã¬ãã§å³ããã®ã§ããããžã§ã¯ãã®ãã£ã¬ã¯ããªäžã«.rubocop.yml
ãã¡ã€ã«ãäœæãããã®äžã«èšå®ãèšè¿°ãããšãRuboCopã¯èšå®ãã¡ã€ã«ãåªå
ããã®ã§ãçšããå æžã«ãªããŸãã
cd ãããžã§ã¯ãã®ãã£ã¬ã¯ããª
touch .rubocop.yml
# .rubocop.ymlãã¡ã€ã«ã«é©åãªèšå®ãæžã蟌ã
# 解æã®å®è¡
rubocop ãã¡ã€ã«å
# ãã¡ã€ã«åãæå®ããªãå Žåã¯ãã£ã¬ã¯ããªäžã®å
šãã¡ã€ã«ã察象ãšããŸãã
â»éç解æããŒã«ã®ããããããŸã§ãå€ãªç©ºçœããããŸããããšãããã®å€æ°ã¯ã©ãããã䜿ãããŠããŸãããããªã©ã®ãã³ãŒãã£ã³ã°ã«ãŒã«ã«åŸã£ãŠããããã®ãã§ãã¯ãäžå¿ã§ãããå®è¡æã®ãšã©ãŒããã£ããé²ãã§ãããæ§è³ªã®ãã®ã§ã¯ãããŸããã
åè