Day 13 – Putting the Pieces together
Alright, we’re back to Ruby. My apologies for slowing down, and with only 8 days to go. Let’s jump right into day 13.
On the outset, Slagell explains the notion of Ruby being a ‘glue language’, like Perl. A language coordinating multiple programs or processes. Historically, AppleScript has been my glue of choice. AppleScript’s strength is also it’s greatest weakness – it’s not a real programming language. On the other side, I’m still looking for a comparable Windows-based scripting language.
I was first exposed to dot syntax back when Macromedia shoehorned it into Director’s Lingo language. It took me exactly 1 project to appreciate the simplicity and power. After that, it was REALbasic which has a great dot syntax. Especially useful for asking about files things – can I write to you? are you a folder? do you exist?
Rather than the FileName.exists
syntax I’m accustomed to, Ruby prefers File.exists?(FileName)
. Though it feels a little backwards, I appreciate the question mark.
Ran into a little trouble today. Not sure what to make of it. Slagell, asks us to create two files, one with a puts
string in it, and one with a string manipulation in it.
I was able to get them working just fine in the Terminal with: > ruby file.rb
He then uses the pipe character to route a string through the string manipulator: > system("echo foo | repeat.rb")
Terminal responded with: Badly placed ()'s
Hmmmm. Not what I expected. Removing the ()’s returned: No such file or directory
Perhaps one of you following along could illuminate me.
In the last exercise for today, my Ruby didn’t like the line:
Dir.entries(dir)
map {|f| File.join(dir,f)}.
to parse through a directory structure. It gave me a undefined method `map` for main:Object
error. Odd I thought, so I read ahead and combined the two lines into:
Dir.entries(dir).map {|f| File.join(dir,f)}.
Looks like the map
method needs an explicit list of things to go through. Good to know. Dot syntax to the rescue.
Tonight’s Soundtrack included:
‘Sing for the Moment‘ – Eminem
‘Alright‘ – Kinnie Star
Next, we officially start week 23. Exciting.
This post documents my journey through Sam’s Teach Yourself Ruby in 21 days. I’ll be joining Al Abut in his effort to learn Ruby and blog along the way.