Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last iteration of loop is incomplete #2293

Open
rabdelazim opened this issue Nov 2, 2023 · 2 comments
Open

Last iteration of loop is incomplete #2293

rabdelazim opened this issue Nov 2, 2023 · 2 comments

Comments

@rabdelazim
Copy link

I noticed a strange behavior the other day. I'm looping through some JSON to print out certain elements but for some reason, PRY does not print the last line of the JSON file. The only thing that seemed to get the print statement to work was to specify it twice. So here is my code for example:

1         def chart(depth=0)
2            print self.name 
3             self.behaviors.each do |b|
4                print  "\n" + "  "*(depth+1) + "|" + b['name']
5             end
6             depth += 1
7            
8             for child in self.children 
9                 print "\n" + "  "*depth + "+--"
10                child.chart(depth)
11            end
12        end

What happens in PRY is that the last set of behaviors (lines 3-5) does not execute. If I were to repeat the same loop a second time, the behaviors all show up twice as expected.
This isn't an issue with my code because when I run the code outside of PRY, there are no missing elements.

@andrehjr
Copy link
Member

andrehjr commented Nov 3, 2023

HI @rabdelazim, how does the last line looks at the terminal?

I think this related to 'print' and new lines. For example:

[1] pry(main)> print "foo"
foo=> nil

@rabdelazim
Copy link
Author

rabdelazim commented Nov 6, 2023

The end of the output in pry looks like this:

    |caching
  +--content type based caching
=> 

EDIT: To be perfectly accurate, the output after the => shows the contents of the file I was working with as expected.

I'm expecting |customBehavior. Here is how it looks in the terminal (as opposed to pry):

    |caching
  +--content type based caching
    |customBehavior% 

(note the % denoting the end of the output)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants