Draft of Assignment 3 with the first milestone almost done
October 31, 2008 | Filed Under Uncategorized | Comments
I’ve posted a draft of #3 — the ZIP is coming. Have to do a bit more work and then it will be out.
The draft is here: http://e168f08.plugh.org/assignments/assignment-3-2/
Lecture 6 and migrations1 ZIP
October 23, 2008 | Filed Under Announcements | Comments
I’ve posted the PDF for Lecture 6 and the ZIP for the migrations1 example on the downloads page.
Assignment 2B (optional!) on Assignments page
October 21, 2008 | Filed Under Announcements | Comments
I’ve added a draft of Assignment 2B — which is optional — to the assignments page. This is done “cookbook” style, with a key portion for you to do on your own. It leverages a ZIP called e168-ar-skel-jgn-10000.zip which you can find on the downloads page.
I may tweak it a bit before Wednesday night.
Again, it’s optional. I believe, though, that after hearing the lecture Wednesday night and after studying the ar-skel download, you can get this down in less than an hour.
Status on Assignment 2?
October 14, 2008 | Filed Under Announcements | Comments
Method Name Lookup
October 10, 2008 | Filed Under Uncategorized | Comments
Last lecture we discussed how Ruby method names are implicitly looked up against “self”. This normally works as you would like, but one case where this can be problematic is when the method name ends in =. For example:
class Something
def whatever=(x)
# do something with x
end
def another_fun
# ...
# it's not clear if we're calling the method self.whatever=(5)
# or trying to create a new variable named "whatever"
# and assigning 5 to it. If you are trying to call the method,
# you should explicitly prefix with the receiver "self."
whatever = 5
# ...
end
end
Assignment 2: Mention of “low ace”
October 7, 2008 | Filed Under Uncategorized | Comments
I wrote what’s below to the Google group, but apparently some did not see it. So read it below.
The back-story is sort of amusing: Last year I wrote the assignment complete with the links to Wikipedia, etc. Amy and I both did sample solutions. When we compared solutions, Amy had implemented a soution that could handle Aces whether they were high or low — mine only did the high Ace. It turned out that in my code, at least, the two Aces created a lot of special cases in the code, and last year’s students didn’t really learn a huge amount from accomodating the low ace (which was optional anyway). So this year I did away with it.
—–
Folks,
In the instructions and in the file hand.rb there is mention of handling a low ace.
Ignore it. I thought I had eradicated all references to it, but it turns out there were a couple of stray mentions.
In this assignment, aces are always high.
I will [likely] modify the assignment so that you are not distracted by this, but the key point is that hand.rb should look like this:
require File.join(File.dirname(__FILE__), 'constants')
# Representation of a hand of cards
class Hand
def initialize(name=nil)
end
end
John
Windows: May need to update to rake 0.8.3
October 5, 2008 | Filed Under Uncategorized | Comments
Folks,
One of you has reported an error from rake that looks like this:
Unable to determine home path environment variable. C:/........./rake.rb:2398: in 'win32_system_dir'
If you get this, try updating rake to version 0.8.3:
gem update rake
John
Slides for Lecture 3 Available in Downloads
October 5, 2008 | Filed Under Announcements | Comments
Folks,
I’ve uploaded a ZIP with Lecture 3 — Actually I’m combining all of the HTML lectures into one ZIP, so it includes both Lectures 2 and 3.
I added some slides — they are marked with the note “[Added Slide]“; there are also some modified slides, that have a note as well. In the slides for Lecture 3, you will also find a link to the handout. Also in the ZIP is handout.rb, which is executable code you can play around with.
Here’s the direct link:
John
Assignment 2; quick note on private methods
October 2, 2008 | Filed Under Announcements | Comments
Folks,
Four things:
- Assignment 2 (the first part; there will be an additional part involving a database later on), is available on the downloads page. The instructions are in the ZIP at instructions/rdoc/index.html
- If you had the issue with assignment 0 where you had to change “gem” to “gem.bat” could you e-mail me (john at 7fff dot com)? I want to use y’all as testers. A problem we had last year was with ZIPPING up the project, and it is exacerbated by certain Windows setups.
And third, about private methods:
As I said in class, subclasses can access private methods in the superclass. A couple of you doubted this, but it is true. The Pickaxe isn’t very clear on it. Here’s an example:
class One
private
def meth
puts 'hi'
end
end
class Two < One
def user_of_meth
meth
end
end
two = Two.new
two.user_of_meth
As you can see, Two#user_of_meth is calling One#meth (which is private). What private really means is that you can’t put an object to the left of a dot; you can only call a private method on “self” (which we haven’t discussed yet), and self has access to all superclass methods. In any case, it is as I described it in lecture. OK?
In most languages, protected methods are for allowing “nearby” classes access. So, typically, the superclass will mark a method as “protected” so that subclasses can get at it. As you can see above, “private” already gets you some of that. What “protected” does, additionally, in Ruby, is allow access to subclasses of a common ancestor. And you can put in a receiver. Officially, “A protected method defined by a class C may be invoked on an object o by a method in an object p if and only if the classes of o and p are both subclasses of, or equal to, the class C” (The Ruby Programming Language, p. 233).
What does this mean to you? It means that you can define a cluster of related classes that have access to one another.
Fourth, I will be posting the lecture slides soon. I need to patch them up a bit. I may post the slides immediately relevant to the one-liners, and the post a revised version.
That’s it!
John
Handout for Lecture 3
October 1, 2008 | Filed Under Announcements | Comments
Folks,
I’ve created a handout for lecture 3 — distance students take note.
I’ve put it here for now:
http://e168f08.plugh.org/lecture3-example.html
Notice the line numbers. I do know that it’s hard to see the screen sometimes from the live feed; when I discuss code this time, I will try to refer to line numbers on this page.
I will likely tweak it a bit before lecture, so if you plan to print it out, do it close to 7 PM or so eastern time.
John