Ruby Debugger code for going into next line - ruby-on-rails

I am working on ROR app , with ruby debugger. This is my code:
def render(d)
debugger
folder=d.folders
folders,empty_folders=check_empty_folder(folder)
c = cost(folders)
end
Now in console the break point at folders=d.folders . Now if i do next near around 30 times then it come to next line in this function folders,empty_folders after going through different ruby source file.
Is there any command I can simply go into next line of function in spite of source code.

Related

"function arguments expected near 'levelc'" when using LOVE

I'm currently trying to make a level loading system for a game.
function love.filedropped(file)
ofile=io.open(file:getFilename(),"r")
io.input(ofile)
file:close
levelc=io.read()
for i=1,levelc do
levels[i]=io.read()
print levels[i]
end
levelc should be the first line of the file, and file:getFilename is the file to open (path included) the project gives an error message on startup, and i've used a similar structure before, but for an output. The error is at line 30, which is the levelc=io.read().
I've tried changing the name of the file pointer (it was "f" before, now "ofile") and i've tried using io.read("*l") instead of io.read() but same result.
EDITS:
-this is a love.filedropped(file)
-i need to open other files from a .txt later and i don't really understand how do do that
The parameter given by love.filedropped is a DroppedFile.
In your case helpful could be File:lines().
For example:
function love.filedropped(file)
-- Open for reading
file:open("r")
-- Iterate over the lines
local i = 0
for line in file:lines() do
i = i + 1
levels[i] = line
print(i, levels[i]) -- Notice the parentheses missing in your code
end
-- Close the file
file:close()
end
Notice that love2d usually only allows reading/writing files within the save or working directory. Dropped files are an exception.
Unrelated to this answer but things I noticed in your code:
Use locals, oFile should be local
file:close() required parentheses as its a function call
Same for the print
The filedropped callback has no end
You mentioned reading other files too, to do so, you can either:
Use love.filesystem.newFile and a similar approach as before
The recommended one-liner love.filesystem.lines

How to copy multiple lines of code into byebug?

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.
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.
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
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.

code blocks don't work in Spyder (Anaconda3)

I am a beginner in Python using Spyder to code from Anaconda3.
I tried to enter such codes in Spyder (Python 3.7). I pressed "Enter" when trying to split the codes and the indents appear auto. But it always returns with "SyntaxError: invalid syntax" and "SyntaxError: 'return' outside function".
E.g. 1
data = {'state':['Ohio','Ohio','Ohio','Nevada','Nevada','Nevada'],
'year':[2000,2001,2002,2001,2002,2003],
'pop':[1.5,1.7,3.6,2.4,2.9,3.2]}
When I press F9 in either line, it returns "SyntaxError: invalid syntax".
E.g. 2
def f(x):
return pd.Series([x.min(),x.max()],index=['min','max'])
Press F9 to run the line, it returns "SyntaxError: unexpected EOF while parsing". If in the second line, it returns "SyntaxError: 'return' outside function".
In addition, I also tried to put "\"s at the end of each line. It doesn't work either. And find from webpages that if the lines end with : or , then you don't need \ to split.
But!!! if I deleted the 'Enters' and put everything in a single line without splits, it works well totally.
Why my python cannot work with code blocks? How can I fix it with Anaconda3?
Thank you so much~~~~
The problem is that you need to select the entire function before pressing F9, if you select only a part of it it will raise an error
You can use \ at the end of each line to tell Python that the line continues below:
data = {\
'state':['Ohio','Ohio','Ohio','Nevada','Nevada','Nevada'],\
'year':[2000,2001,2002,2001,2002,2003],\
'pop':[1.5,1.7,3.6,2.4,2.9,3.2]\
}
Having the dictionary split across multiple lines may look pretty, but it is not proper syntax. I've also been tripped up by tutorials that show their dictionaries like that :|
This may not work in interpreters other than IDLE.

Rails Console output breaks when modifying

Totally lacking intuition here.
First i thought i only happens when copying and pasting code from editor. Unfortunately it's more common. Only thing I am doing is trying to insert more code somewhere in the middle of current input or modifying it.
Expected behavior:
Modify input without side effects.
What actually happens:
VERY OFTEN when modifying input it gets messed up.
If that happens every key press will copy and insert current input alongside with pressed character.
Vital notes:
Encoding is set to UTF-8 in terminal(s)
Issue persists on different emulators ( Terminator, gnome-terminal )
Issue persists when using different Ruby runtime console ( IRB, Pry )
Issue appears to be related to Ruby runtime, NOT Linux shell (i guess...)
Issue appears since:
Since system install. Didn't appear on my MacBook Air
System:
ArchLinux, although coworker reported same thing happens on his MacBook Pro.
How to reproduce (works for me):
Open rails console
Type example code: Shift.where(name: "som").where(name: "dom").where(name: "pom")
Navigate cursor to modify first where statement.
Change "som" to "SOM"
Should see it break
Press random key repeatedly to see it break even more.
Images:
Good input
Now i will navigate to first where statement to change "som" to uppercase "SOM"
I basically navigated my cursor and pressed SHIFT+S, SHIFT+O, SHIFT+M
Hope it's clear enough :-)
Thank you!
EDIT 1:
Tried using zsh instead of bash, didn't help
Disabled spring gem, didn't help
EDIT 2:
Folks on reddit suggested that i should check if there are any Ruby readline warnings eg. "Readline is not installed". None of them appear anywhere. Also reinstalled ruby 2.4.1, seems like it's not the problem in my case.
EDIT 3:
I cannot reproduce the issue in a different Rails project.
Issue appears on Rails 5.1.1, meanwhile 5.0.3 works flawlessly.
Is it possible that Rails itself (or rather one of its gems) can be the cause?
I had a very similar issue, and I boiled it down to my coloring.
I had the following in my IRBRC:
class String
def _colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
_colorize(31)
end
def yellow
_colorize(33)
end
end
IRB.conf[:PROMPT][:MY_PROMPT] = {
:AUTO_INDENT => true, # enables auto-indent mode
:PROMPT_I => "[ME]".red + " > ".yellow, # normal prompt
:PROMPT_S => "[ME]".red + " ".yellow, # prompt for continuated strings
:PROMPT_C => "[ME]".red + " * ".yellow, # prompt for continuated statement
:RETURN => "[ME]".red + "=> ".yellow + "%s\n".red # format to return value
}
IRB.conf[:PROMPT_MODE] = :MY_PROMPT
And when I removed the .red and .yellow, everything was just fine.
I think it's because my coloring characters like \e[31m was getting counted as a length 5 characters instead of 0 characters.
My solution was to remove my coloring for the time being. Hopefully someone will come up with a better solution than that.

Nokogiri cannot exit opening a url

When I try in pry (which is a substitute for IRB or rails console)
doc = Nokogiri::HTML(open(url))
It reads the file (although I have to keep pressing space bar). However, at the end, it says
(END)
and it doesn't return the command line back to me.
What do I need to do to exit this and get back to the prompt?
type q to exit less viewer. the result of Nokogiri::HTML is too long so you are seeing result bypassing less command

Resources