如何使用 byebug 來除錯 Ruby 程式

3f7d9611fc919c98512b779cde637dfc?s=47 Johnlin
August 02, 2020

如何使用 byebug 來除錯 Ruby 程式

3f7d9611fc919c98512b779cde637dfc?s=128

Johnlin

August 02, 2020
Tweet

Transcript

  1. ೗Կ࢖༻ byebug ိআ ࡨ Ruby ఔࣜ John Lin

  2. ᮫ԙզ • John Lin • Twitter: @johnlinvc • Senior Solution

    Architect, DevOps 
 @ West Pharmaceutical Service (୆ᖯҖ๏෰຿)
  3. Լࡌ໢ᅿ • ౤Өย࿨ఔࣜᛰ౎์ࡏ https://git.io/JJVqt • େ֓ੋṜݸ talk ࠷༗༻తҰ ทɻ

  4. ৗݟత debug ໰୊ • ෆ֬ఆ๭ஈఔࣜ။ෆ။ඃࣥߦ౸ɻ • ෆ֬ఆᏓᏐతᆴੋଟগɻ • ෆ֬ఆᏓᏐੋࡏ䬟ཫඃमվతɻ •

    ෆ֬ఆ౸ఈݺڣ౸ྃ䬟Ұஈఔࣜɻ • ෆ֬ఆ䬟ཫݺڣṜҰஈఔࣜɻ
  5. ৗݟత debug ํ๏ • ؃/፺ਘ code => ࢖༻ਓᡵฤᩄث/௚ᩄثɻ • ࢖༻

    puts େ๏ɻ • ࢖༻আࡨثɻ
  6. ྖંၢ݊ coupon.rb def get_coupon(user_id, history) if history[user_id] = true return

    0 end history[user_id] = true 3000 end puts get_coupon(1, {}) Ṝछศᑍࢴཫ౎ੋఔࣜᛰ
  7. ྖંၢ݊ coupon.rb $ ruby coupon.rb 0 def get_coupon(user_id, history) if

    history[user_id] = true return 0 end history[user_id] = true 3000 end puts get_coupon(1, {}) Ṝछศᑍࢴཫ౎ੋఔࣜᛰ →৭ᐽཫੋbash/byebug ࿨༬ظෆಉɼጯ֘ཁ༌ग़ 3000
  8. ༻ puts ֬ೝఔࣜ။ෆ။ඃࣥߦ౸ def get_coupon(user_id, history) if history[user_id] = true

    return 0 end puts "here" history[user_id] = true 3000 end puts get_coupon(1, {}) ೗Ռ༗ࣥߦ౸Ṝཫब။༌ग़ here
  9. ༻ puts ֬ೝఔࣜ။ෆ။ඃࣥߦ౸ $ ruby coupon_here.rb 0 def get_coupon(user_id, history)

    if history[user_id] = true return 0 end puts "here" history[user_id] = true 3000 end puts get_coupon(1, {}) ೗Ռ༗ࣥߦ౸Ṝཫब။༌ग़ here ᔒ༗ hereɼ
 ॴҎᔒ༗ࣥߦ౸ਖ਼֬తҐஔ
  10. byebug • ໋ྩྻత Ruby আࡨثɻ • ࢖༻ TracePoint API ိሣ

    Ruby ఔࣜআࡨɻ • ࢧԉ MRI Ruby 2.4.0 Ҏ্ɻ ෆࢧԉ jruby, rubinius ౳ଖଞ Ruby ௚ᩄثɻ
  11. ॄኄੋআࡨث • Ұछ༻ԙআࡨଖሏఔࣜతిᡵఔࣜٴ޻۩ɻ(from wiki) • ఏڙதᏗᴍɼᄸ㑊ࣥߦɼᒾࢹᏓᏐ ౳ޭೳɻ

  12. ҆᧋ • ࢖༻ bundler ိ҆᧋ • ࡏ Gemfile ཫՃೖ 


    gem 'byebug' • ࣥߦ bundle install
  13. ࢖༻ byebug root@coscup:/app# byebug coupon.rb [1, 9] in /app/coupon.rb =>

    1: def get_coupon(user_id, history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug)
  14. ᙘ໘ղ㘸 root@coscup:/app# byebug coupon.rb [1, 9] in /app/coupon.rb => 1:

    def get_coupon(user_id, history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) 䈕໊᪑ߦᏐൣᅴ
  15. ᙘ໘ղ㘸 root@coscup:/app# byebug coupon.rb [1, 9] in /app/coupon.rb => 1:

    def get_coupon(user_id, history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) ఔࣜᛰ࿨ߦᥒ
  16. ᙘ໘ղ㘸 root@coscup:/app# byebug coupon.rb [1, 9] in /app/coupon.rb => 1:

    def get_coupon(user_id, history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) ඪࣔ໨લ
 ఀࢭҐஔ
  17. ᙘ໘ղ㘸 root@coscup:/app# byebug coupon.rb [1, 9] in /app/coupon.rb => 1:

    def get_coupon(user_id, history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) prompt ɼඪࣔ䬟زߦੋզ၇༌ೖతࢦྩ
  18. None
  19. ཭։ byebug [1, 9] in /app/coupon.rb => 1: def get_coupon(user_id,

    history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) quit Really quit? (y/n) y root@coscup:/app#
  20. help • byebug ༗㚎ݐ㘸໌ࢦྩɻ • ࡏ prompt ༌ೖ help बՄҎ؃౸ࢦྩྻදɻ

    (byebug) help
  21. help (byebug) help break -- Sets breakpoints in the source

    code catch -- Handles exception catchpoints condition -- Sets conditions on breakpoints continue -- Runs until program ends, hits a breakpoint or reaches a line debug -- Spawns a subdebugger delete -- Deletes breakpoints disable -- Disables breakpoints or displays display -- Evaluates expressions every time the debugger stops down -- Moves to a lower frame in the stack trace edit -- Edits source files enable -- Enables breakpoints or displays finish -- Runs the program until frame returns frame -- Moves to a frame in the call stack help -- Helps you using byebug history -- Shows byebug's history of commands info -- Shows several informations about the program being debugged interrupt -- Interrupts the program irb -- Starts an IRB session kill -- Sends a signal to the current process list -- Lists lines of source code method -- Shows methods of an object, class or module next -- Runs one or more lines of code pry -- Starts a Pry session quit -- Exits byebug restart -- Restarts the debugged program save -- Saves current byebug session to a file set -- Modifies byebug settings show -- Shows byebug settings skip -- Runs until the next breakpoint as long as it is different from the current one source -- Restores a previously saved byebug session step -- Steps into blocks or methods one or more times thread -- Commands to manipulate threads
  22. help • byebug ༗㚎ݐ㘸໌ࢦྩɻ • ࡏ prompt ༌ೖ help बՄҎ؃౸ࢦྩྻදɻ

    • ࡏ prompt ༌ೖ help <ࢦྩ> बՄҎ؃౸ࢦྩత㘸໌ɻ (byebug) help (byebug) help help
  23. h[elp] (byebug) help help h[elp][ <cmd>[ <subcmd>]] Helps you using

    byebug help -- prints a summary of all commands help <cmd> -- prints help on command <cmd> help <cmd> <subcmd> -- prints help on <cmd>'s subcommand <subcmd> [ ] 㚎త෦෼ੋબᎩੑతɼॴҎ໵ՄҎ୞ଧ h
  24. l[ist] • ؃ݱࡏࣥߦ౸䬟Ұߦࢦྩɻ။༌ग़ෟۙతزߦɻ (byebug) list [1, 9] in /app/coupon.rb =>

    1: def get_coupon(user_id, history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {})
  25. b[reak] • ཁٻ byebug ࡏࣥߦ౸ࢦఆߦᏐલఀԼိɻఀԼိతҐஔɼ ላ໊ڣ၏ ”தᏗᴍ“
 • ໵ՄҎ༻؆ሜ b


    (byebug) break 2 Created breakpoint 1 at /app/coupon.rb:2 (byebug) b 3 Created breakpoint 3 at /app/coupon.rb:3
  26. continue • c[ontinue] ࢦྩ။ᩋ࢑ఀతఔࣜ៺᠃ࣥߦɼ௚౸۰౸ԼҰݸ தᏗᴍҝࢭɻ (byebug) continue

  27. ༻ byebug ֬ೝఔࣜ။ෆ။ඃࣥߦ౸ [1, 9] in /app/coupon.rb => 1: def

    get_coupon(user_id, history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) break 5 Created breakpoint 1 at /app/coupon.rb:5 (byebug) ૝֬ఆ။ࣥߦୈ 5 ߦ
  28. ༻ byebug ֬ೝఔࣜ။ෆ။ඃࣥߦ౸ [1, 9] in /app/coupon.rb => 1: def

    get_coupon(user_id, history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) break 5 Created breakpoint 1 at /app/coupon.rb:5 (byebug) ཁٻࡏࣥߦୈ 5 ߦ࣌ఀԼိ
  29. ༻ byebug ֬ೝఔࣜ။ෆ။ඃࣥߦ౸ [1, 9] in /app/coupon.rb => 1: def

    get_coupon(user_id, history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) break 5 Created breakpoint 1 at /app/coupon.rb:5 (byebug) continue ཁٻ៺᠃ࣥߦ
  30. ༻ byebug ֬ೝఔࣜ။ෆ။ඃࣥߦ౸ [1, 9] in /app/coupon.rb => 1: def

    get_coupon(user_id, history) 2: if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) break 5 Created breakpoint 1 at /app/coupon.rb:5 (byebug) continue 0 root@coscup:/app# ᔒ༗ఀԼိब݁ଋྃɼॴҎୈ 5 ߦੋᔒ༗ࣥߦ౸తɻ
  31. n[ext] • ࣥߦݱࡏṜߦఔࣜɻฒ׌ࡏԼҰߦఀԼိɻ • ՄҎ؃౸ԼҰߦ။ࣥߦਙኄɻ • ༻puts େ๏త࿩ཁࡏ㑌Ұݸ෼ࢧᴍ౎ putsɻ

  32. [1, 9] in /app/coupon.rb 1: def get_coupon(user_id, history) => 2:

    if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) next [1, 9] in /app/coupon.rb 1: def get_coupon(user_id, history) 2: if history[user_id] = true => 3: return 0 4: end ݱࡏࣥߦ౸ୈ 2 ߦ
  33. [1, 9] in /app/coupon.rb 1: def get_coupon(user_id, history) => 2:

    if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) next [1, 9] in /app/coupon.rb 1: def get_coupon(user_id, history) 2: if history[user_id] = true => 3: return 0 4: end ࣥߦԼҰߦ
  34. [1, 9] in /app/coupon.rb 1: def get_coupon(user_id, history) => 2:

    if history[user_id] = true 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) next [1, 9] in /app/coupon.rb 1: def get_coupon(user_id, history) 2: if history[user_id] = true => 3: return 0 4: end ݱࡏࣥߦ౸ྃୈࡾߦ
  35. ෆੋ㑌ݸ஍ํ౎ೳதᏗ • ༗Ұࠣᔒ༗ࣥߦҙٛత஍ํੋෆೳதᏗతɻ૾ੋۭߦɼ end, {, }ɻ (byebug) break /app/coupon.rb:4 ***

    Line 4 is not a valid breakpoint in file /app/coupon.rb. Valid break points are: [B] 1: def get_coupon(user_id, history) [B] 2: if history[user_id] = true [B] 3: return 0 4: end ᔒ༗ඪ [B] తߦᏐແ๏தᏗ
  36. ࡏಛఆ৘گԼ break • ՄҎ୞༗ࡏಛఆత৘گԼ break • break [file:]line [if <expr>]


    (byebug) break 3 if history[user_id] Created breakpoint 5 at /app/coupon.rb:3
  37. ࡏ rails server ༻ byebug • rails 4.2 ೭ޙब༬ઃࡏ։ᚙ໛ࣜ҆᧋ byebug

    • ࡏ code ཫ࢖༻ byebug method ိࡏࣥߦఔࣜత࣌ީఀࡏ byebug ႔ɻ • ඇ rails తఔࣜ require 'byebug' ޙ໵Մ༻ byebug methodɻ • ෆա byebug method ෆࢉੋதᏗᴍɻ
  38. ࡏ rails ཫ࢖༻ byebug Started GET "/posts" for 127.0.0.1 at

    2020-08-01 12:18:37 +0000 Processing by PostsController#index as */* [3, 12] in /app/rails_example/app/controllers/ posts_controller.rb 3: 4: # GET /posts 5: # GET /posts.json 6: def index 7: byebug => 8: @posts = Post.all 9: end 10: 11: # GET /posts/1 12: # GET /posts/1.json (byebug) ။ఀࡏ byebug తԼҰߦ
  39. ࡏඇ rails ཫ࢖༻ byebug $ ruby coupon_byebug.rb [1, 10] in

    /app/coupon_byebug.rb 1: require 'byebug' 2: def get_coupon(user_id, history) 3: byebug => 4: if history[user_id] = true 5: return 0 6: end 7: history[user_id] = true 8: 3000 9: end 10: (byebug) ઌ require ࠽ೳ࢖༻ byebug
  40. ᑍ݅ࣜ byebug • code ཫత byebug बੋҰൠత ruby methodɻՄҎ์ࡏ೚ Կ஍ํɼ໵ՄҎ༻

    if ိઃఆᑍ݅ ɻ
 $ ruby coupon_byebug_cond.rb [1, 10] in /app/coupon_byebug_cond.rb 1: require 'byebug' 2: def get_coupon(user_id, history) 3: byebug if user_id == 1 => 4: if history[user_id] = true 5: return 0 ୞༗ᑍ݅ූ߹࣌࠽தᏗ
  41. • ෆ֬ఆ๭ஈఔࣜ။ෆ။ඃࣥߦ౸ɻ • ෆ֬ఆᏓᏐతᆴੋଟগɻ • ෆ֬ఆᏓᏐੋࡏ䬟ཫඃमվతɻ • ෆ֬ఆ౸ఈݺڣ౸ྃ䬟Ұஈఔࣜɻ • ෆ֬ఆ䬟ཫݺڣṜҰஈఔࣜɻ

    ৗݟత debug ໰୊
  42. ༻ puts ֬ೝᏓᏐతᆴ def get_coupon(user_id, history) if history[user_id] = true

    puts user_id puts history return 0 end history[user_id] = true 3000 end puts get_coupon(1, {}) $ ruby coupon_puts_val.rb 1 {1=>true} 0
  43. ༻ byebug ֬ೝᏓᏐతᆴ [1, 9] in /app/coupon.rb 1: def get_coupon(user_id,

    history) 2: if history[user_id] = true => 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) user_id 1
  44. [1, 9] in /app/coupon.rb 1: def get_coupon(user_id, history) 2: if

    history[user_id] = true => 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) history 1 help 2 help help 3 list
  45. [1, 9] in /app/coupon.rb 1: def get_coupon(user_id, history) 2: if

    history[user_id] = true => 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) history 1 help 2 help help 3 list
  46. ᙛ࿨㚎ݐࢦྩিಥ࣌ɼ ࢖༻ eval [1, 9] in /app/coupon.rb 1: def get_coupon(user_id,

    history) 2: if history[user_id] = true => 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) eval('history') {1=>true}
  47. v[ar] • v[ar] args ɿྻग़ method తჩᏐɻ • v[ar] c[onst]

    ɿྻग़ݱࡏ scope 㚎త constantɻ • v[ar] i[nstance] [object] ɿྻग़ object ҃ੋ self త ivarɻ • v[ar] l[ocal]ɿྻग़ॴ༗ local ᏓᏐɻ • v[ar] a[ll]ɿྻग़ local, global, instance ᏓᏐɻ
  48. [1, 9] in /app/coupon.rb 1: def get_coupon(user_id, history) 2: if

    history[user_id] = true => 3: return 0 4: end 5: history[user_id] = true 6: 3000 7: end 8: 9: puts get_coupon(1, {}) (byebug) var local history = {1=>true} user_id = 1
  49. ෆ୞᧺࡯ɼؐՄҎհೖ [1, 2] in /app/modify_var.rb => 1: a = 1

    2: puts "a is: #{a}" (byebug) n [1, 2] in /app/modify_var.rb 1: a = 1 => 2: puts "a is: #{a}" (byebug) a = 56 56 (byebug) c a is: 56 a = 1 puts "a is: #{a}"
  50. • ෆ֬ఆ๭ஈఔࣜ။ෆ။ඃࣥߦ౸ɻ • ෆ֬ఆᏓᏐతᆴੋଟগɻ • ෆ֬ఆᏓᏐੋࡏ䬟ཫඃमվతɻ • ෆ֬ఆ౸ఈݺڣ౸ྃ䬟Ұஈఔࣜɻ • ෆ֬ఆ䬟ཫݺڣṜҰஈఔࣜɻ

    ৗݟత debug ໰୊
  51. ༻ puts ፙᏓᏐඃमվతҐஔ def get_coupon(user_id, history) puts history if history[user_id]

    = true puts history return 0 end history[user_id] = true 3000 end puts get_coupon(1, {}) $ ruby coupon_puts_find.rb {} {1=>true} 0
  52. ༻ byebug ፙᏓᏐඃमվతҐஔ (byebug) display history 1: history = (undefined)

    (byebug) set linetrace linetrace is on (byebug) continue Tracing: /app/coupon.rb:9 puts get_coupon(1, {}) 1: history = (undefined) Tracing: /app/coupon.rb:2 if history[user_id] = true 1: history = {} Tracing: /app/coupon.rb:3 return 0 1: history = {1=>true}
  53. display expr • ࡏ఍ୡ㑌ݸதᏗᴍత࣌ީɼ။ࣗಈࣥߦ exprɻ • expr ՄҎ༗෭࡞༻ɻdisplay x+=1 ။վᏓఔࣜཫ

    x తᆴɻ
  54. ༻ byebug ፙᏓᏐඃमվతҐஔ (byebug) display history 1: history = (undefined)

    (byebug) set linetrace linetrace is on (byebug) continue Tracing: /app/coupon.rb:9 puts get_coupon(1, {}) 1: history = (undefined) Tracing: /app/coupon.rb:2 if history[user_id] = true 1: history = {} Tracing: /app/coupon.rb:3 return 0 1: history = {1=>true}
  55. set linetrace • ࣗಈࡏ㑌Ұߦఔࣜ࢑ఀ೭ޙཱࠁࣥߦɻ౥഑ display expr बՄҎࡏ㑌Ұߦఔࣜ౎ࣥߦ expr ိ؂߇ఔࣜࣥߦաఔɻ •

    set nolinetrace ՄҎ᮫ᎃɻ
  56. ༻ byebug ፙᏓᏐඃमվతҐஔ (byebug) display history 1: history = (undefined)

    (byebug) set linetrace linetrace is on (byebug) continue Tracing: /app/coupon.rb:9 puts get_coupon(1, {}) 1: history = (undefined) Tracing: /app/coupon.rb:2 if history[user_id] = true 1: history = {} Tracing: /app/coupon.rb:3 return 0 1: history = {1=>true}
  57. ༻ byebug ፙᏓᏐඃमվతҐஔ (byebug) display history 1: history = (undefined)

    (byebug) set linetrace linetrace is on (byebug) continue Tracing: /app/coupon.rb:9 puts get_coupon(1, {}) 1: history = (undefined) Tracing: /app/coupon.rb:2 if history[user_id] = true 1: history = {} Tracing: /app/coupon.rb:3 return 0 1: history = {1=>true}
  58. ༻ byebug ፙᏓᏐඃमվతҐஔ (byebug) display history 1: history = (undefined)

    (byebug) set linetrace linetrace is on (byebug) continue Tracing: /app/coupon.rb:9 puts get_coupon(1, {}) 1: history = (undefined) Tracing: /app/coupon.rb:2 if history[user_id] = true 1: history = {} Tracing: /app/coupon.rb:3 return 0 1: history = {1=>true}
  59. • ෆ֬ఆ๭ஈఔࣜ။ෆ။ඃࣥߦ౸ɻ • ෆ֬ఆᏓᏐతᆴੋଟগɻ • ෆ֬ఆᏓᏐੋࡏ䬟ཫඃमվతɻ • ෆ֬ఆ౸ఈݺڣ౸ྃ䬟Ұஈఔࣜɻ • ෆ֬ఆ䬟ཫݺڣṜҰஈఔࣜɻ

    ৗݟత debug ໰୊
  60. ౸ఈݺڣྃ䬟Ұஈఔࣜ? require_relative 'hidden_lib.rb' puts HiddenLib.new.hello("world") $ grep 'hello' hidden_lib.rb $

    ፙෆ౸ hello Ṝݸࣈ۲ʁʁ $ ruby method_caller.rb called hello with args: ["world"]
  61. ౸ఈݺڣྃ䬟Ұஈఔࣜ? # method_caller.rb require_relative 'hidden_lib.rb' puts HiddenLib.new.hello("world") $ grep 'hello'

    hidden_lib.rb $ ፙෆ౸ hello Ṝݸࣈ۲ʁʁ $ ruby method_caller.rb called hello with args: ["world"]
  62. class HiddenLib # hidden_lib.rb def method_missing(name, *args) "called #{name} with

    args: #{args.map(&:to_s)}" end end ౸ఈݺڣྃ䬟Ұஈఔࣜ? # method_caller.rb require_relative 'hidden_lib.rb' puts HiddenLib.new.hello("world") ׬શᔒ༗ hello Ṝݸࣈ۲ʂʂ $ ruby method_caller.rb called hello with args: ["world"]
  63. "ஶ໊"త method_missing • method_missing ੋᙛ object ඃݺڣෆଘࡏత method ɼब ။վҝݺڣṜݸ

    methodɻඃݺڣత method ໊᜝࿨ሏతჩ Ꮠ౎။ੋ method_missing తჩᏐɻ Ruby on Rails ࢖༻ྃ ෆগత method_missingɻ • obj.foo(a,b) => obj.method_missing(:foo, [a,b])
  64. class HiddenLib # hidden_lib.rb def method_missing(name, *args) "called #{name} with

    args: #{args.map(&:to_s)}" end end ༻ puts ፙඃݺڣతఔࣜ # method_caller.rb require_relative 'hidden_lib.rb' puts HiddenLib.new.hello("world")
  65. ༻ byebug ፙඃݺڣతఔࣜ [1, 3] in /app/method_caller.rb 1: require_relative 'hidden_lib.rb'

    2: => 3: puts HiddenLib.new.hello("world") (byebug) step [1, 5] in /app/hidden_lib.rb 1: class HiddenLib 2: def method_missing(name, *args) => 3: "called #{name} with args: #{args.map(&:to_s)}" 4: end 5: end (byebug)
  66. s[tep] [1, 3] in /app/method_caller.rb 1: require_relative 'hidden_lib.rb' 2: =>

    3: puts HiddenLib.new.hello("world") (byebug) step [1, 5] in /app/hidden_lib.rb 1: class HiddenLib 2: def method_missing(name, *args) => 3: "called #{name} with args: #{args.map(&:to_s)}" 4: end 5: end (byebug) • ᄸ㑊ࣥߦਐೖඃݺڣత methodɻ
  67. • ෆ֬ఆ๭ஈఔࣜ။ෆ။ඃࣥߦ౸ɻ • ෆ֬ఆᏓᏐతᆴੋଟগɻ • ෆ֬ఆᏓᏐੋࡏ䬟ཫඃमվతɻ • ෆ֬ఆ౸ఈݺڣ౸ྃ䬟Ұஈఔࣜɻ • ෆ֬ఆ䬟ཫݺڣṜҰஈఔࣜɻ

    ৗݟత debug ໰୊
  68. framework vs library Framework త code զ၇త code զ၇త code

    Library త code
  69. ୭ݺڣྃṜҰஈఔࣜ? $ ./framework hello # my_code.rb def my_method "hello" end

  70. ༻ puts ፙݺڣ႔ $ ./framework (eval):1:in `<main>' ./framework:4:in `eval' ./framework:4:in

    `<main>' hello # my_code.rb def my_method puts caller_locations "hello" end
  71. ༻ byebug ፙݺڣ႔ ./framework [1, 5] in /app/my_code.rb 1: require

    'byebug' 2: def my_method 3: byebug => 4: "hello" 5: end (byebug) where
  72. ༻ byebug ፙݺڣ႔ ./framework [1, 5] in /app/my_code.rb 1: require

    'byebug' 2: def my_method 3: byebug => 4: "hello" 5: end (byebug) where
  73. ༻ byebug ፙݺڣ႔ ./framework [1, 5] in /app/my_code.rb 1: require

    'byebug' 2: def my_method 3: byebug => 4: "hello" 5: end (byebug) where
  74. w[here] • ᰖࣔ໨લత call stack ɼ0 ੋ໨લඃݺڣత methodɻᏐࣈ େతݺڣᏐࣈখతɻ ex:

    1 ݺڣ 0ɻ (byebug) where --> #0 Object.my_method at /app/my_code.rb:4 #1 <main> at /app/(eval):1 ͱ-- #2 Kernel.eval at /app/framework:4 #3 <main> at /app/framework:4
  75. • ෆ֬ఆ๭ஈఔࣜ။ෆ။ඃࣥߦ౸ɻ • ෆ֬ఆᏓᏐతᆴੋଟগɻ • ෆ֬ఆᏓᏐੋࡏ䬟ཫඃमվతɻ • ෆ֬ఆ౸ఈݺڣ౸ྃ䬟Ұஈఔࣜɻ • ෆ֬ఆ䬟ཫݺڣṜҰஈఔࣜɻ

    ৗݟత debug ໰୊
  76. bye ࢦྩখঞ • h[elp] [cmd] • q[uit] • l[ist] •

    b[reak] [file:]line [if expr] • c[ontinue] • n[ext] • v[ar] l[ocal] • s[tep] • disp[lay] expr • set linetrace • w[here]
  77. ݁࿦ • byebug ՄҎ㢨ॿզ၇ߋշߋํศ஍ፙग़ఔࣜత໰୊ɻ • ՄҎ࢖༻ byebug ိڠॿզ၇ཧղఔࣜӡ࡞ɻಛผੋᯩଶ෼ ੳᔒ㭎๏႔ཧత෦㟨ɻ

  78. Q&A ౤Өย࿨ఔࣜᛰ: https://git.io/JJVqt John Lin Twitter: @johnlinvc