re text editor

Good day all a question perhaps some experienced Ruby users would see
what I am missing. Have to submit a text editor with a simple chosen
paragraph for class. I run the code in ATOM comes back zero errors. I get
all the breakdown of sentences, lines, words etc however the ideal
sentences in the summary just don't populate at the end. I thought it might
be the chosen paragraph so picked another one with the same result. Any
ideas are much appreciated.
Attached a txt if anyone has a moment.

Thank you
Rgds
Jason

RubyLang.txt (2.74 KB)

You are reassigning `text =` after reading it from a file, whi H is why it is always the same result.

···

On Oct 26, 2021, at 09:14, JY JY <jason.thickett0008@gmail.com> wrote:

Good day all a question perhaps some experienced Ruby users would see what I am missing. Have to submit a text editor with a simple chosen paragraph for class. I run the code in ATOM comes back zero errors. I get all the breakdown of sentences, lines, words etc however the ideal sentences in the summary just don't populate at the end. I thought it might be the chosen paragraph so picked another one with the same result. Any ideas are much appreciated.
Attached a txt if anyone has a moment.

Thank you
Rgds
Jason

RubyLang.txt (2.74 KB)

First off, I didn’t run or debug the program, but a couple things jumped out at me when I looked at it:

1) You assigned a constant string to the variable “text”, and then read in a file and reassigned the contents to the “text” variable. You then separated the lines and recombined them in the variable “text”. This is a “code smell”.

2) Your “stop words” are defined with embedded commas. “%w” uses spaces as delimiters so you should drop the commas.

Finally, you have several consecutive assignments, any of which could be the source of the problem. I suggest you print the result of each assignment to determine which one is the source of the problem. Alternatively, use IRB or another debugger to look at those variables as they are assigned.

I’d rather "teach you to fish” than hand you a cooked fish ready to eat. Good fishing!

···

On Oct 26, 2021, at 9:36 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:

You are reassigning `text =` after reading it from a file, whi H is why it is always the same result.

On Oct 26, 2021, at 09:14, JY JY <jason.thickett0008@gmail.com> wrote:

Good day all a question perhaps some experienced Ruby users would see what I am missing. Have to submit a text editor with a simple chosen paragraph for class. I run the code in ATOM comes back zero errors. I get all the breakdown of sentences, lines, words etc however the ideal sentences in the summary just don't populate at the end. I thought it might be the chosen paragraph so picked another one with the same result. Any ideas are much appreciated.
Attached a txt if anyone has a moment.

Thank you
Rgds
Jason

<RubyLang.txt>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Hey Jason,

I don't want to do your homework for you :wink: It was smart to ask for help,
though!

In IRB, `ideal_sentences` does have a value, so I'm not sure I understand
exactly what issue you're facing with that piece of the code.

Working through the code line-by-line, I think I know what you're trying to
achieve, but the "code smell" that Ryan and Jack have pointed to is likely
causing unexpected behavior:

text = %q{
In Harry’s world fate works ...
}

and

lines = File.readlines("text.txt")
line_count = lines.size
text = lines.join

It may surprise you if you add a `puts text` to the next line; regardless
of what you assign to the `text` variable on the first line, you will be
working with the contents of `text.txt` because you are re-assigning that
variable.

There is likely a better way to organize this code so that this sort of bug
is less likely. In cases like this, writing some basic unit tests might be
helpful too!

Feel free to email me directly if you'd like some guidance on writing a
test or two for this little script!

···

On Tue, Oct 26, 2021 at 11:58 AM Jack Royal-Gordon <jackrg@pobox.com> wrote:

First off, I didn’t run or debug the program, but a couple things jumped
out at me when I looked at it:

1) You assigned a constant string to the variable “text”, and then read in
a file and reassigned the contents to the “text” variable. You then
separated the lines and recombined them in the variable “text”. This is a
“code smell”.

2) Your “stop words” are defined with embedded commas. “%w” uses spaces as
delimiters so you should drop the commas.

Finally, you have several consecutive assignments, any of which could be
the source of the problem. I suggest you print the result of each
assignment to determine which one is the source of the problem.
Alternatively, use IRB or another debugger to look at those variables as
they are assigned.

I’d rather "teach you to fish” than hand you a cooked fish ready to eat.
Good fishing!

> On Oct 26, 2021, at 9:36 AM, Ryan Davis <ryand-ruby@zenspider.com> > wrote:
>
> You are reassigning `text =` after reading it from a file, whi H is why
it is always the same result.
>
>> On Oct 26, 2021, at 09:14, JY JY <jason.thickett0008@gmail.com> wrote:
>>
>> 
>> Good day all a question perhaps some experienced Ruby users would see
what I am missing. Have to submit a text editor with a simple chosen
paragraph for class. I run the code in ATOM comes back zero errors. I get
all the breakdown of sentences, lines, words etc however the ideal
sentences in the summary just don't populate at the end. I thought it might
be the chosen paragraph so picked another one with the same result. Any
ideas are much appreciated.
>> Attached a txt if anyone has a moment.
>>
>> Thank you
>> Rgds
>> Jason
> <RubyLang.txt>
>>
>>
>> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
>> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Thank you all for the feedback it has given some clues for sure. I removed
some of code blocks to test see where maybe the issues are. When running
ideal sentences code with the paragraph only works without issues. When
adding above code all what is being asked works just fine gives breakdowns
of sentences words etc. However then the ideal sentences code block that
did print to screen on its own now doesn't print in the summary. So still
have some digging but all your inputs definitely helped point in the right
direction.

Thank you
Rgds
Jason

···

On Tue., Oct. 26, 2021, 1:25 p.m. Jacob Herrington, < jacobherringtondeveloper@gmail.com> wrote:

Hey Jason,

I don't want to do your homework for you :wink: It was smart to ask for help,
though!

In IRB, `ideal_sentences` does have a value, so I'm not sure I understand
exactly what issue you're facing with that piece of the code.

Working through the code line-by-line, I think I know what you're trying
to achieve, but the "code smell" that Ryan and Jack have pointed to is
likely causing unexpected behavior:

text = %q{
In Harry’s world fate works ...
}

and

lines = File.readlines("text.txt")
line_count = lines.size
text = lines.join

It may surprise you if you add a `puts text` to the next line; regardless
of what you assign to the `text` variable on the first line, you will be
working with the contents of `text.txt` because you are re-assigning that
variable.

There is likely a better way to organize this code so that this sort of
bug is less likely. In cases like this, writing some basic unit tests might
be helpful too!

Feel free to email me directly if you'd like some guidance on writing a
test or two for this little script!

On Tue, Oct 26, 2021 at 11:58 AM Jack Royal-Gordon <jackrg@pobox.com> > wrote:

First off, I didn’t run or debug the program, but a couple things jumped
out at me when I looked at it:

1) You assigned a constant string to the variable “text”, and then read
in a file and reassigned the contents to the “text” variable. You then
separated the lines and recombined them in the variable “text”. This is a
“code smell”.

2) Your “stop words” are defined with embedded commas. “%w” uses spaces
as delimiters so you should drop the commas.

Finally, you have several consecutive assignments, any of which could be
the source of the problem. I suggest you print the result of each
assignment to determine which one is the source of the problem.
Alternatively, use IRB or another debugger to look at those variables as
they are assigned.

I’d rather "teach you to fish” than hand you a cooked fish ready to eat.
Good fishing!

> On Oct 26, 2021, at 9:36 AM, Ryan Davis <ryand-ruby@zenspider.com> >> wrote:
>
> You are reassigning `text =` after reading it from a file, whi H is why
it is always the same result.
>
>> On Oct 26, 2021, at 09:14, JY JY <jason.thickett0008@gmail.com> wrote:
>>
>> 
>> Good day all a question perhaps some experienced Ruby users would see
what I am missing. Have to submit a text editor with a simple chosen
paragraph for class. I run the code in ATOM comes back zero errors. I get
all the breakdown of sentences, lines, words etc however the ideal
sentences in the summary just don't populate at the end. I thought it might
be the chosen paragraph so picked another one with the same result. Any
ideas are much appreciated.
>> Attached a txt if anyone has a moment.
>>
>> Thank you
>> Rgds
>> Jason
> <RubyLang.txt>
>>
>>
>> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
>> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;