17 Jul, 2009, Runter wrote in the 41st comment:
Votes: 0
I'm pretty sure you can use Ruby in windows without needing to deal with cygwin in the first place?
17 Jul, 2009, flumpy wrote in the 42nd comment:
Votes: 0
Runter said:
I'm pretty sure you can use Ruby in windows without needing to deal with cygwin in the first place?


yes, yes you can.

however its not nearly as nice as it is when running on a nix like environment.

I for one had a hell of a time trying to set up the cygwin installation of ruby. I never did get it running. I guess if it comes as a package installed by cygwin that must be the way to go, but the one provided on the ruby site didn't work at all…

I like ruby as a language. I don't particularly want to learn it, it's not a native JVM language for one thing. However I am finding that I have to learn it, because of work. :(

I also find the lack of dev environments and no (free) textmate a big issue for 'dows.

ho hum.

interestingly tho, ruby is why I am learning groovy… java just isn't dynamic, and the transition was too big for my liking. A partially dynamically typed language was a good thing for me. Ruby was like being stuck in Javascript land all over again blech… now it looks a bit more paletable.
17 Jul, 2009, Runter wrote in the 43rd comment:
Votes: 0
flumpy said:
I don't particularly want to learn it, it's not a native JVM language for one thing.


That's…surprising? *Also points out jruby*
17 Jul, 2009, Runter wrote in the 44th comment:
Votes: 0
flumpy said:
however its not nearly as nice as it is when running on a nix like environment.


Why? As far as I know you can run the same code out of windows in ruby with no change.
17 Jul, 2009, Chris Bailey wrote in the 45th comment:
Votes: 0
There is not a lack of Ruby IDE's as far as I know. It doesn't have textmate of course, but neither does Linux. They refuse to produce their superior product for anything but Mac OS, grr! SciTe makes a good "lite" editor in windows, and there is always NetBeans. Most of your favorite IDE's have plugins or whatever to handle Ruby, and they do it well. Personally I use Gedit with several plugins like the file pane browser, syntax highlighting, line numbers, shortcuts, bracket matching and line highlighting(There are probably more that I'm forgetting). It makes for an extremely light weight but full featured IDE that is highly customizable. The only thing similar to Textmate on Windows is E-Text Editor, which looks very nice (but uses cygwin!), and it's commercial.
17 Jul, 2009, David Haley wrote in the 46th comment:
Votes: 0
gVim works on all platforms… :wink:
18 Jul, 2009, Runter wrote in the 47th comment:
Votes: 0
I guess why I can't really empathize is because I don't use a fancy IDE.
18 Jul, 2009, Idealiad wrote in the 48th comment:
Votes: 0
Chris Bailey said:
SciTe makes a good "lite" editor in windows, and there is always NetBeans.


I second a recommendation of SciTe for Windows users, it's what I use for Python and I think it's excellent. Also for Windows I think there's a separate file browser plugin, which I don't use, but puts it between the lite-editor and IDE option.
18 Jul, 2009, Igabod wrote in the 49th comment:
Votes: 0
I am using SciTe since it's what came with the ruby download.

I realized after all that business with the cygwin debate that I don't even need it, but whatever. No harm no foul I guess.

Ok so I couldn't sleep today for some reason so I got to work on writing a program in ruby that does the 99 bottles of beer on the wall song. I'm kinda proud of it cause I did it without looking at any tutorials or anything. So I felt like posting it on here and getting some input on it.

#count set to 10 for the abbreviated version, just uncomment the count = 99 below and comment out the other one for the full version.
#count = 99
count = 10
command = ' '

while count != 0
puts count.to_s+ ' bottles of beer on the wall, ' +count.to_s+ ' bottles of beer!'
count = count - 1
puts 'You take one down and pass it around, ' +count.to_s+ ' bottles of beer on the wall.'
sleep 1
puts ' '
end
puts 'No more beer on the wall, No more beer.'
puts 'The guys fall down, I stagger around. No more beer to be found.'
puts ' '

while command.downcase != 'quit'
puts 'Please type quit to exit this program.'
command = gets.chomp
end


One question I had is, is there a ruby equivalent of the C \r\n ? cause it kinda sucks having to put extra lines of code for just a blank line. I'd like to be able to puts 'The next line is a blank line\r\n' using only one \r\n since puts throws one in there anyway. I know the \ is the escape character for ruby too, but when I tried \r\n it just displayed the \r\n instead of giving a new line.
18 Jul, 2009, Runter wrote in the 50th comment:
Votes: 0
Either way irb isn't going to display it like you are expecting on return values. But here's the answer to the your question:

"\r\n" ### expands escapes, subs, format str, etc

'\r\n' ### does not expand and is literal


To make it actually print it instead of just str.inspect from return in irb….use print "str" or puts "str"
18 Jul, 2009, Metsuro wrote in the 51st comment:
Votes: 0
I made a testing2.rb with one line puts "test\r\ntest2" and did ruby testing2.rb and got…

[Sat Jul 18 04:44:39 Strakc@li101-39:~ ] $ ruby testing2.rb
test.
test2
[Sat Jul 18 04:44:45 Strakc@li101-39:~ ] $
18 Jul, 2009, Runter wrote in the 52nd comment:
Votes: 0
I also don't mind seeing…I guess I got used to it in C++. Probably could make a singleton for endl if you really wanted to. :P

ENDL = "\r\n"

print "ROAR!!!" + ENDL
18 Jul, 2009, Igabod wrote in the 53rd comment:
Votes: 0
Ok, I see so I just need to use the double quotes instead of single quotes when I want to do \r\n\r\n nice. Thanks.

Anybody have any critiques of my 99 bottles program? Anything I can do better or that I didn't need to do? Keeping in mind that I'm still working my way through a basic tutorial for beginners.
18 Jul, 2009, Metsuro wrote in the 54th comment:
Votes: 0
the while thing seems odd, I remember a different way to do the loop its like .foreach or something?
18 Jul, 2009, Igabod wrote in the 55th comment:
Votes: 0
what's so odd about it? it says while the count doesn't equal 0 send the first message, reduce the count by one, then send the 2nd message. It's pretty much the same as it would be in C.
18 Jul, 2009, Idealiad wrote in the 56th comment:
Votes: 0
I don't know if this is thought of the same way in Ruby, but it could be considered bad practice to use a while when you are iterating over a fixed array size anyway.
18 Jul, 2009, Chris Bailey wrote in the 57th comment:
Votes: 0
There is nothing wrong with while in particular, personally for that I would use downto, which is kind of neat.
99.downto(0) {|i| puts i}
18 Jul, 2009, Igabod wrote in the 58th comment:
Votes: 0
well this program was suggested by the tutorial as a test so I'm thinking it is okay. The page that suggests it is http://pine.fm/LearnToProgram/?Chapter=0.... It's down at the bottom of a page that has just gone over while and if/else statements.
18 Jul, 2009, Chris Bailey wrote in the 59th comment:
Votes: 0
This might contain some useful things for you to try out. Maybe =P
class BeerSinger
attr_reader :count
def initialize count
@count = count
end

def sing_line
if @count > 0
puts "#@count bottles of beer on the wall, #@count bottles of beer!\r\n"
remove_beer
puts "You take one down and pass it around, #@count bottles of beer on the wall.\r\n"
sleep 1
else
puts "No more beer on the wall, No more beer.\r\n"
puts "The guys fall down, I stagger around. No more beer to be found.\r\n"
sleep 1
end
end

def remove_beer
@count -= 1
end
end

puts "How many beers are on the wall?"
bs = BeerSinger.new(gets.chomp.to_i)
bs.count.downto(0) {bs.sing_line}
18 Jul, 2009, Igabod wrote in the 60th comment:
Votes: 0
defining remove_beer seems kinda pointless to me since it's only one line and is only used once in the program. And why set the class and all that stuff at the beginning?

Some of that stuff is a little bit more advanced than my skill is but my familiarity with C allows me to know what it's doing (somewhat). But I'm trying to stick with doing these programs using only the stuff the tutorial has taught me so far. Once I finish with this tutorial I'll begin trying to do the same programs in different ways, but till then I just wanna learn how to do the basic stuff.

Though looking over your version of that program again, I like the if method better than the while method for this type of thing. Your program has more lines of actual code in it than mine though with all that extra stuff at the beginning and the un-needed def of remove_beer. If I condense my program down, removing un-needed blank lines and commented out lines, I am using 14 lines. Seems more efficient this way. Is there some reason more efficient isn't a good thing in this case?

P.S. You did give me a few ideas on how to make some of my other piddly little programs better though, thank you for that.
40.0/79