Wednesday, December 21, 2011

Working with the Method method in Ruby

So with the help of my friend Z (also known as Chris to some, mostly just his wife) I've made some progress on Dungeon Crawler. But not much.

Namely, he showed me how to abstract my routing, so rather than having

get "/torch_room" do
  @torch_room = torch_room
  erb :torch_room
end


I have a method that automatically builds a route based on methods that already exist for rooms. Pretty awesome! I think learning to be less specific and abstracting my code is one of the most difficult things I'm learning. One of the guiding tenets of Ruby is DRY (Don't Repeat Yourself) and I really just need to be aware when I'm writing the same basic code more than once that it can probably be abstracted.

Ok, but here's my problem. I still can't figure out a way to collect input from a form, pass that input into an instance variable so that I can check it from other rooms and perform redirects based on the input itself. Does that make sense? I am absolutely trying my hardest to be clear about what I'm trying to do. Z also clued me in on a Method method but I can't figure that out, either.

Here's a gist with what I've done so far, but (FAIR WARNING) it's straight up busted:

Busted Gist

That said, I've noticed a funny thing about this problem. Bear in mind I've been wrestling with this guy off and on since my last post. (I DID do a couple of fun tutorials in between wrestling matches, mostly to keep myself limbered up) I didn't get frustrated in the usual "FUCK IT I GIVE UP" kind of way, but more in a "huh that didn't work. Ok let's try another thing. Hmm nope, that didn't work either," kind of way.

I did try some CRAZY other things, based on what my friend Miles told me about last time I posted about this problem (said crazy things mostly involved working with hashes, trying to convert hashes to strings, etc. Does that work? PROBABLY, I DON'T KNOW!) with minimal success.

I think this is how Daniel-san felt when he realized the entire time he thought he was washing Mr. Miyagi's car, he was actually learning karate.

No comments:

Post a Comment