Thông thường chúng ta muốn debug trong ruby thì hay sử dụng các gem pry, debugger, byebug. Nhược điểm là phải sử dụng thêm thư viện bên ngoài. Còn ở bài viết này mình sẽ chia sẻ thêm 1 cách mà không cần sử dụng thư viện bên ngoài mà vẫn có thể debug được.
Ruby
# door.rb
class Door
def initialize
@open = false
binding.irb
puts "Is the door open: #{@open}"
end
end
Door.newKết quả:
Ruby
Documentos/scripts/ruby via 💎 v3.2.2
❯ ruby door.rb
From: door.rb @ line 4 :
1: class Door
2: def initialize
3: @open = false
=> 4: binding.irb
5: puts "Is the door open: #{@open}"
6: end
7: end
8:
9: Door.new
irb(#<Door:0x00007fa9a0f367a8>):001> @open
=> false
irb(#<Door:0x00007fa9a0f367a8>):002> @open=true
=> true
irb(#<Door:0x00007fa9a0f367a8>):003> exit
Is the door open: trueHappy coding! =]]z
3 comments
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.info/ru/register-person?ref=O9XES6KU
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://www.binance.info/register?ref=IHJUI7TF