How to copy multiple lines of code into byebug?

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-27 05:59:25

问题


byebug doesn't seem to be able to handle multiple lines of code.

Example

I put byebug into the controller, and the next lines of code are (these could be anything, just an example here):

    payment_intent = Stripe::PaymentIntent.create({
      payment_method_types: ['card'],
      amount: @amount_minor_unit,
      currency: @currency,
      application_fee_amount: 123, # STODO
      transfer_data: {
        destination: @star.stripe_account,
      },
    })

But it does this:

If the code is edited so it's on one single line, it succeeds:

payment_intent = Stripe::PaymentIntent.create({payment_method_types: ['card'],amount: @amount_minor_unit,currency: @currency,application_fee_amount: 123, transfer_data: {destination: @star.stripe_account,},})

But this manual editing is extremely tedious. How can I make byebug accept multiple lines of code so that I can copy/paste directly from somewhere like a controller into the byebug-halted rails server?

Other ideas

After pressing ctrl+d in the console to exit byebug, then the browser errors, then I can copy code into the browser, but the same thing happens, where it accepts the code if it's all on one line:

..but otherwise errors with the same syntax error as above.


回答1:


I use the gem pry-byebug and it has the behaviour you want, you can paste multiple lines of code without it executing right away.

https://github.com/deivid-rodriguez/pry-byebug

You can just add it to your gem file and set break points with binding.pry




回答2:


what works for me is Just copy all the code in one and paste it to the browser where we paste the link don't click enter. it will format it in one line. then just copy and paste in the byebug cli.




回答3:


The comments have already given you the answer, but I will formalize it here.

Instead of trying to copy and paste the line of code you want to execute, you can just use step to take a "step" through the code. Byebug's documentation gives you a list of commands you can use. Step will run your program one line at a time.

def index
  byebug
  init_item = {
    a: "foo", b: "bar"
  }
  // omitted code

Entering the breakpoint above, init_item will be nil. The command step (or s) will advance the code one line, and after that, init_item will be initialized to what we specify.

Sometimes the byebug will enter a few lines "down", but using up (for going up the callstack) will let you navigate to the line you're interested in.

There's no need to copy-paste code into byebug, you can just step through it.



来源:https://stackoverflow.com/questions/65057449/how-to-copy-multiple-lines-of-code-into-byebug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!