# My First Application

**URL:** <https://www.ruby-forum.com/t/my-first-application/194434>\
**Category:** Ruby\
**Created:** [September 6, 2010, 5:58am UTC](https://www.ruby-forum.com/t/my-first-application/194434 "2010-09-06T05:58:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdhale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jdhale](https://www.ruby-forum.com/u/jdhale)\
**Post date:** [September 6, 2010, 5:58am UTC](https://www.ruby-forum.com/t/my-first-application/194434/1 "2010-09-06T05:58:28Z")

</div>

I have worked with PHP in the past and have been playing with Ruby for a  
few weeks. I made a program that I would love to get feedback on. Any  
comments would be great. I have my program on Git hub.

[http://github.com/jasonhamilton/NZBMatrix-Downloader](http://github.com/jasonhamilton/NZBMatrix-Downloader)

---

<div class="post-metadata">

**Author:** ![jdhale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jdhale](https://www.ruby-forum.com/u/jdhale)\
**Post date:** [September 6, 2010, 11:23am UTC](https://www.ruby-forum.com/t/my-first-application/194434/2 "2010-09-06T11:23:37Z")

</div>

Jason H. wrote:

> I have worked with PHP in the past and have been playing with Ruby for a  
> few weeks. I made a program that I would love to get feedback on. Any  
> comments would be great. I have my program on Git hub.
> 
> [http://github.com/jasonhamilton/NZBMatrix-Downloader](http://github.com/jasonhamilton/NZBMatrix-Downloader)

Well, the conversion isn’t accurate yet, but using your approach, here’s  
another way to do it that allows you to easily grow the list of numerals  
to be converted:

def convert(b10number)

numerals = [‘M’,‘D’,‘C’,‘L’,‘X’,‘V’,‘I’]  
values = [1000,500,100,50,10,5,1]  
implemented = []  
conversion = “”  
remainder = b10number

values.each do |this\_value|  
if this\_value \> 1  
implemented \<\< remainder/this\_value  
remainder = remainder % this\_value  
else  
implemented \<\< remainder  
end  
end

implemented.each\_with\_index do |this\_many, indx|  
conversion += (numerals[indx] \* this\_many)  
end

puts conversion  
end

puts ‘Howdy there, enter a number and I'll convert it to the older  
Roman Numeral fashion!’  
argument = gets.chomp.to\_i  
convert argument

---

<div class="post-metadata">

**Author:** ![jdhale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jdhale](https://www.ruby-forum.com/u/jdhale)\
**Post date:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/my-first-application/194434/3 "2010-09-06T16:39:38Z")

</div>

On Mon, Sep 6, 2010 at 6:01 AM, Jason H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I have worked with PHP in the past and have been playing with Ruby for a  
> few weeks. I made a program that I would love to get feedback on. Any  
> comments would be great. I have my program on Git hub.
> 
> [http://github.com/jasonhamilton/NZBMatrix-Downloader](http://github.com/jasonhamilton/NZBMatrix-Downloader)

Quick feedback:

- Variables that start with $ are global variables. Try to avoid them,  
and specially in a program like this I think they are not needed. Make  
them local variables, and replace the few that you use inside the  
class with an instance variable that you set when creating the  
instance.

- For an infinite loop: loop do {}, instead of while 1==1

- I can’t see how you exit the loop

- In the loop body, there’s too much detailed processing of the  
message, calling to\_s, downcase and indexing several times. There’s  
probably a way to DRY that up, but I’m in a rush right now.

If I have more time later I will comment a bit more.

Hope this helps,

Jesus.

---

<div class="post-metadata">

**Author:** ![jdhale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jdhale](https://www.ruby-forum.com/u/jdhale)\
**Post date:** [September 6, 2010, 6:32pm UTC](https://www.ruby-forum.com/t/my-first-application/194434/4 "2010-09-06T18:32:44Z")

</div>

JesÃºs Gabriel y GalÃ¡n wrote:

> - Variables that start with $ are global variables. Try to avoid them,  
> and specially in a program like this I think they are not needed. Make  
> them local variables, and replace the few that you use inside the  
> class with an instance variable that you set when creating the  
> instance.

How can I get the variables into the class then?

> - For an infinite loop: loop do {}, instead of while 1==1
> 
> - I can’t see how you exit the loop

I would like the user to be able to exit the loop by pressing a button  
or something like that but I’m not sure how to do that without messing  
up the looping.

> - In the loop body, there’s too much detailed processing of the  
> message, calling to\_s, downcase and indexing several times. There’s  
> probably a way to DRY that up, but I’m in a rush right now.

Thanks for your your feedback Jesus.

---

<div class="post-metadata">

**Author:** ![jdhale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jdhale](https://www.ruby-forum.com/u/jdhale)\
**Post date:** [September 6, 2010, 6:29pm UTC](https://www.ruby-forum.com/t/my-first-application/194434/5 "2010-09-06T18:29:22Z")

</div>

> Well, the conversion isn’t accurate yet, but using your approach, here’s  
> another way to do it that allows you to easily grow the list of numerals  
> to be converted:

Thanks Greg

---

<div class="post-metadata">

**Author:** ![jdhale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jdhale](https://www.ruby-forum.com/u/jdhale)\
**Post date:** [September 6, 2010, 6:44pm UTC](https://www.ruby-forum.com/t/my-first-application/194434/6 "2010-09-06T18:44:15Z")

</div>

On Mon, Sep 6, 2010 at 6:32 PM, Jason H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Jesús Gabriel y Galán wrote:
> 
> > - Variables that start with $ are global variables. Try to avoid them,  
> > and specially in a program like this I think they are not needed. Make  
> > them local variables, and replace the few that you use inside the  
> > class with an instance variable that you set when creating the  
> > instance.
> 
> How can I get the variables into the class then?

Pass them in the initialize method if they are variable or use  
Constants inside the class, if they are harcoded values.

> > - For an infinite loop: loop do {}, instead of while 1==1
> > 
> > - I can’t see how you exit the loop
> 
> I would like the user to be able to exit the loop by pressing a button  
> or something like that but I’m not sure how to do that without messing  
> up the looping.

If you have some work to do that you don’t want to stop to ask the  
user for input, you should use threads or processes. You launch a  
thread or process to do the work and present a menu to the user in the  
main thread to control the job.

> > - In the loop body, there’s too much detailed processing of the  
> > message, calling to\_s, downcase and indexing several times. There’s  
> > probably a way to DRY that up, but I’m in a rush right now.
> 
> Thanks for your your feedback Jesus.

BTW, nice job with your first application, looks really good for a first  
try.

Jesus.
