Confessions of a Ruby Newbie

A former computer programmer turned stay-at-home-mom attempts to teach herself Ruby.

Thursday, August 18, 2005

My first program

Well, I didn't have to set up my environment because my geek husband beat me to the punch, on all three of our computers! So, I got to go straight to coding. Today I actually wrote my very first ruby program. It took some playing with irb to understand it (and I still have a long way to go, I think), but here's what happened:

irb(main):001:0> d= Dir.new(".")
=> #
irb(main):002:0> d.each {|name| puts "#{name}"}
.
..
2005-08-06 110530 DSCF0726.JPG
2005-08-06 110540 DSCF0727.JPG
2005-08-06 110546 DSCF0728.JPG
2005-08-06 110608 DSCF0729.JPG
2005-08-06 110624 DSCF0730.JPG
=> #
irb(main):003:0>

Woohoo - a directory listing! I'm really on my way now. Of course, I quickly discovered that
irb(main):001:0> Dir.foreach(".") {|x| puts "#{x}"}
does the same thing. Okay, so now I get class methods vs. instance methods. Ahem, moving right along...

0 Comments:

Post a Comment

<< Home