[Courses] [Ruby] Lesson 0: Installing, References, and your first
homework assignment
Mel Chua
mallory.chua at students.olin.edu
Tue Nov 8 14:38:52 EST 2005
Hi, I'm Mel. This is my first class. I'm an electrical engineering
student at Olin College in Boston, and don't know as much about coding
as my friends seem to believe, but I'm trying to fix that. I was sort of
the token "coder girl" in high school and tend more towards theory than
hacking, and I'm also trying to tip that balance to the other side. I
want to learn how to mess with things and not be afraid of blowing up my
computer, darn it.
I've worked with C++, C, Python, and Scheme, but never got too in-depth
with any of them, though I loved Python's
"just-hack-it-together"-ability and the way Scheme makes you think
differently than any other language I've seen. Ruby piqued my interest
because I've heard it's a beautiful yet powerful little language, and
wanted to learn more. I've been meaning to play with Ruby On Rails, so I
figured this might be a good place to start before launching into that.
Homework the First - I tried looking at wiki.rb from the Instiki source
code (a wiki written in Ruby - it's spiffy, and I'd like to learn how it
works). Thankfully, it's well-commented and cleanly-written. I still
have no idea what is going on, but here are my guesses.
This is code for something called a Word, which is a type of WikiLink.
It's any group of letters that fits the wiki_word_pattern, whatever that
is. If the code finds that the wiki word is escaped, it'll mark the
entire inputted word as escaped; otherwise it marks nothing as escaped
and cranks the entire thing through, hooking it up to a link of the same
name. I can't tell you what individual lines of code do, though.
#---------- begin code ---------------
# This chunk matches a WikiWord. WikiWords can be escaped
# by prepending a '\'. When this is the case, the +escaped_text+
# method will return the WikiWord instead of the usual +nil+.
# The +page_name+ method returns the matched WikiWord.
class Word < WikiLink
attr_reader :escaped_text
unless defined? WIKI_WORD
WIKI_WORD = Regexp.new('(":)?(\\\\)?(' +
WikiWords::WIKI_WORD_PATTERN + ')\b', 0, "utf-8")
end
def self.pattern
WIKI_WORD
end
def initialize(match_data, content)
super
@textile_link_suffix, @escape, @page_name = match_data[1..3]
if @escape
@unmask_mode = :escape
@escaped_text = @page_name
else
@escaped_text = nil
end
@link_text = WikiWords.separate(@page_name)
@unmask_text = (@escaped_text || @content.page_link(@page_name,
@link_text, @link_type))
end
end
More information about the Courses
mailing list