March 2012
6 posts
I discovered something interesting today. Kudos to Craig for leading me to this discovery.
Method names and variables are really the same thing. Both point to some object that is being returned. This makes more sense now that I know it, but we proved it in IRB below.
We first create a class Person that is initialized with a name property and make the name accessible outside.
1.9.3p125 :067 > class Person
1.9.3p125 :068?> attr_accessor :name
1.9.3p125 :069?> def initialize(name)
1.9.3p125 :070?> @name = name
1.9.3p125 :071?> end
1.9.3p125 :072?> end
We define a method that returns a string “Bob”
1.9.3p125 :073 > def get_name
1.9.3p125 :074?> “Bob”
1.9.3p125 :075?> end
And then we initialize an instance of the Person class with the get_name method.
1.9.3p125 :076 > bob = Person.new(get_name)
=> #<Person:0x00000002ad78a0 @name=”Bob”>
When we call the name property of the instance, we see that it doesn’t return “get_name” which is what we initialized the class with. We get the value that the method returned.
1.9.3p125 :077 > bob.name
=> “Bob”
Taking this one step further, suppose we update our get_name method
1.9.3p125 :078 > def get_name
1.9.3p125 :079?> “Sally”
1.9.3p125 :080?> end
Now, the name property of bob, our instance of the Person class, remains “Bob” because the method wasn’t called again. It returned “Bob” only once when the instance was initialized.
1.9.3p125 :081 > bob.name
=> “Bob”
This nuance may or may not seem important until you think about storing these properties in a database. For example, imagine a 3rd party company that handles customer service for B2Cs. When the 3rd party company hires a new employee, they ask him or her to fill out a form indicating their gender. Based on the gender, they assign a random pseudonym to that employee for all their interactions with customers on the phone or email, etc. One way to assign and store these pseudonyms would be to create two different tables for male and female employees and instantiate records with “Bob” or “Sally” names. There’s no reason to have two different tables other than that, as far as I can tell.
Or, you could have one class and instead of instantiating records with a string, instantiate with a method that assigns “Bob” or “Sally” based on the gender from the input form. The method could also provide extra flexibility and have a set of names instead of having every male employee being assigned “Bob” and every female employee “Sally.”
If I made a mistake in my reasoning above, or if you can add to this, comment below!
December 26th morning in St. Louis. Justin calls me. I don’t pick up. December 26th evening, I call back. He invites me to go to New York City to sell T-shirts on Times Square. He has 1,000 T-shirts and he needs help selling. I say OK. We talk about costs and profits and agree to split everything 50/50. We’re driving.
December 27th, I drive 6 hours back to Whitewater, WI.
December 27th, 11:30pm. Justin, Megan, and I begin our journey.
Justin is tired after driving 3 hours. We stop at a Subway in Chicago. The lone employee is behind bullet proof glass. He’s Indian. We make conversation, he gives me free cookies for solidarity.
I take the wheel.
Indiana. Ohio. Sunrise. It’s 8 am and we smell something burning. It’s definitely our car. Three hours later, twin brothers in a Mercer, Pennsylvania have solved our dilemma by changing a damaged oil filter.
December 28th. We reach our Craigslist roomshare where we have one room the size of a large walk-in closet and a queen bed. We unpack 16 boxes of T-shirts into it. I put up a website in 2 hours while Megan models the T-shirt hoping to be able to sell online.
December 29th, it’s Thursday now. We visit the testicular cancer foundation we’ve decided to donate part of the profits to, if there are any. We visit the office where they give out permits to sell merchandise on the streets.
We are not eligible. We load up duffel bags and backpacks with T-shirts anyway.
It seems as if the whole world is at Times Square when we get there. No one pays us any attention. We set our bags down, look at each other dubiously for a few minutes, and then yell one of the three sentences I will never forget:
“New Year’s Eve 2012!”
“NYE in NYC!”
“What happens in New York, STAYS in New York!”
We have found our rhythm. People are buying. We’re having fun. We have a code word to hide our merchandise and pretend to sightsee when we see a uniform.
We take pictures of everyone who buys a a T-shirt. At 2 am we run out of steam. It seems as if the city is just getting started. $500 new dollars in our pockets, we are feeling good. Until we get back and see that we’ve only gotten rid of one out of the sixteen boxes we brought. We have two days left.
December 30, we have to wake up early and move out of Queens into a room in Jersey City. The house is like an antique shop. Our roommate, a middle aged Ukranian lady is extremely hospitable. She gives us a key and a tour of the house. And we’re back on the streets.
![]()
“New Year’s Eve 2012!”
“NYE in NYC!”
“What happens in New York, STAYS in New York!”
People are delighted. We get smiles and laughs from everyone who see us. Those guys who stand around passing out coupons for Broadway shows and comedy shows warn us not to get caught. They’ve seen others like us get arrested. Some are silently rooting for us, others are resentful of the new kids on their turf. We meet this guy.
We can only carry about 50 T-shirts at a time. Transit time to restock inventory is 2 hours. We cannot split up because we need everyone to carry enough T-shirts back. We realize we did not plan logistics very well. We are on the streets till 4am this time. By the time we get home it’s 7am.
I am too tired to sleep.
December 31st. It’s 11am and we’re supposed to go to Times Square before it gets blocked off. We cannot find the house key. Tatiana, our Ukranian landlord, thinks we are joking. This is the first time she has put up her extra room for rent. She has to get her lock replaced. We lose our deposit.
It is 4pm now. Too late to go to Times Square. We decide we’re done selling. The past two nights have been draining. I go to sleep, Justin and Megan head out to see the ball drop.
I spend New Year’s Eve on a train to visit cousins in Queens. The train is mostly empty, but the conductor, a large, African American youth shouts “Happy New Year” rather gleefully into his megaphone, first inside the train, then out the windows, then at every station. He can’t wait to be off duty so he can go celebrate 2012.
I visit my cousins and stay with family for the night.
January 1st. I meet up with my fellow apparel compatriots. We still have 14 boxes left. We make a feeble attempt to sell them to retailers in the city. They laugh at us.
January 2nd. We load up the car. We’ve made $1247 from T-shirt sales. The trip cost us $1400. We’re in red even before accounting for inventory. The mood is somber. We don’t have much conversation material left.
New Jersey. Pennsylvania. We stop at a rest area. Our car breaks down again. A blizzard starts. We call half a dozen garages. They’re all closed. We find one willing to take a look at the car in the morning. An old man with a tow truck shows up. We try to make conversation. He does not respond.
The garage is in State College, PA. We make our way to the motel the garage manager points us toward. We trek a quarter mile along a dark highway, lugging our suitcases when a truck pulls up and offers us a ride. We’re glad we accepted because the motel is a 15 minute drive at 50 mph.
January 3rd. The garage owner says he can’t have the parts to fix the car till Friday. It’s Tuesday. Justin’s dad calls the garage and suddenly the car can be fixed by Wednesday.
The motel has free wi-fi. I stay in bed all day and catch up on email. We order 60 wings from Pizza Hut and eat them all.
January 4th. The car is ready. We start for home. Ohio. Indiana. Illinois. We attempt to play driving games.
Wisconsin. It’s a sweet sight. I reach home and pass out.
January 5th. Sleep.
January 6th. I reflect on the trip.
Totally worth it.
I moved this post here.