strictures and structures

if only we stopped trying to be happy, we could have a pretty good time

Month: June, 2011

my father speaking fondly of his marriage certificate

“Here, Jane. This is proof that you’re not a bastard!”

Advertisements

Journey to the End of the Night, Checkpoint 1

I jogged into the park, comforted by the sight of all the blue
armbands. 8:19. I’m 11 minutes early. A promising start, and I hadn’t
even seen any chasers on the way–just huge clumps of blue runners.

Standing across from the gleaming stainless steel statue of Saint
Sandwich Day, were a woman in a white lab coat and a hippie with
dreadlocks–could this get any more classically San
Francisco?–surrounded by blue runners. So that was the place to get
stamped.

I waited in line, and when it was my turn, I patiently held out my
map. The hippie turned a stone face to me, and said, “So. What have
you done?”

Done? I’d already jogged more in ten minutes than I had in the whole
past year; wasn’t that enough for him? “What do I have to do?”

He nodded towards the woman in the lab coat. “For her. It’s her
birthday, you know.”

Black-framed, square glasses, curly hair, something that looked like
tie-dye underneath the coat, and a big friendly smile. Fashionably
unfashionable, probably had friends who went to Burning Man even if
she didn’t go herself. Handling this one would require great irony.

“Well,” I said. “I’m so sorry I didn’t bring you a present, but I just
wanted to let you know what a huge honor it is getting a stamp from
you. It’s a very generous and giving gesture of you to be giving out
stamps instead of getting presents on your birthday, but I could tell
by looking at you what a giver you are. It would be so nice to get a
stamp from a generous lady like you.”

She giggled. “You’re good at this!” I got my stamp. It was very nicely
aligned within the box it was supposed to go.

Success! Even if I got tagged before the next checkpoint, I was going
to squeeze fun from this game, every way I could.

I explain alias_method_chain and save the day

Alias_method_chain

Hello. “alias_method_chain” is a Rails-ism that keeps confusing me.
The implementation  looks something like this: 

def alias_method_chain(target, feature)
  alias_method “#{target}_without_#{feature}”, target
  alias_method target, “#{target}_with_#{feature}”
end

I found this weird, but diagramming the method
declarations and what was supposed to happen was very helpful, and now
I get it.

In the diagram, each word outside of a box indicates the method name,
and the word within the box indicates a method implementation. Imagine
that Ruby has a set of boxes that each hold a method implementation,
and each box is labeled with the method’s name. You can change the
method name, but not change the content of the box, and you’ll still
have a method that does the exact same thing–just named differently.

Every time you use “alias_method,” you can think of it as Ruby copying
the box and putting a different method name on it. The previous copy
of the box with the old name still exists. You can redefine a new box
with the old name and it won’t affect the new copy with the different
name.

So in the top part of the diagram, you start with the methods
“feature” and “target.” After you use alias_method_chain on them,
you’ll need to define a method named “target_with_feature” so there’s
a box of “target_with_feature” code to copy to the “target” method
name.

The resulting four boxes in the bottom part of the diagram represent
all the new boxes with their names after we call alias_method_chain,
and define “target_without_feature.”

Pardon the ASCII art, but the Gimp is still downloading.