Silly Programming Mistakes Episode 1
Well, I feel pretty dumb at the moment. I just spent the last 6 hours trying to figure out why I couldn’t seem to use a Ruby Hash correctly and I just could not make it work. I’ve been using ruby for over a year now, and I’ve written plenty of code using hashes, so why was this so hard?
First, let me show you what I was doing. I’m writing a data persistence layer over the Google App Engine Java persistence store so that I can write my JRuby on Rails apps very similar to how you do using ActiveRecord. So I have a model objects and methods for defining properties and relationships on the class. Java is statically typed, so I wanted to ensure the translation from ruby objects to java objects happens correctly. To do this I have mapped the subset of GAE supported java types to a set of ruby symbols. To set up a model object you do the following:
class MyModel < DataAE::Entity
property :id, :key
property :name, :string
property :age, :integer
end
And the DataAE::Entity class has the property function, like so:
@@types = Hash.new
def self.property(name, type)
...
@@types[name] = type
end
Pretty straight forward, right? I’m sure some of you have already figured out my problem, but it took me forever to think of it. Anyway, the “…” part of the method creates attribute accessors based on the name passed in so that you can call “myModel.age” and get the age back and a “myModel.age = 30″ to set the age. This is a little more difficult than it looks though because you have to translate from the type passed into the self.property method to the java type that is stored in GAE. The details of that aren’t that important now except for the first part of the set method. Here it is in it’s broken form:
def ae_set_property(name, value)
type = @@types[name]
…
end
When this is run you get an empty string back. What?!? Clearly in the self.property method I’m storing things in the hash, right? I even did a
@@types.keys.each do |k|
puts k
end
which resulted in
id
name
age
And then I tried
@@types.values.each do |v|
puts v
end
resulting in
key
string
integer
Even the Hash to_s method which should return KeyValueKeyValue… returned
idkeynamestringageinteger
But every single time I tried @@types["id"] I’d get back ”(empty string). It made no sense.
And then it hit me. The self.property method was taking in symbols and storing them in the hash. Then I was using strings to try and access those keys and it wasn’t working! The solution was simple; either store the keys as strings or convert the string to a symbol when calling the [] function. I opted for just storing the key as a string and all is well. The self.property function now looks like this:
def self.property(name, type)
...
@@types[name.to_s] = type
end
Sigh…
dosage of amoxicillin for respiratory disorder…
Buygeneric drugs…
cephalexin dosage for dogs…
Buygeneric drugs…
order cialis in canada online…
Buyno prescription…
Amoxicillin@official.site” rel=”nofollow”>……
Buyno prescription…
allopurinol@and.coumadin” rel=”nofollow”>……
Buygeneric drugs…
avodart@in.usa” rel=”nofollow”>.…
Buyno prescription…
ashwagandha@supplement.now” rel=”nofollow”>……
Buygeneric meds…
Azor@official.site” rel=”nofollow”>……
Buygeneric pills…
atarax@and.hives” rel=”nofollow”>.…
Buygeneric drugs…
Crestor@official.site” rel=”nofollow”>.…
Buywithout prescription…
Chantix@official.site” rel=”nofollow”>.…
Buydrugs without prescription…
generic@Cialis.now” rel=”nofollow”>.…
Buynow…
dicyclomine@and.imodium” rel=”nofollow”>……
Buygeneric drugs…
Depakote@official.site” rel=”nofollow”>……
Buyit now…
depakote@classification.now” rel=”nofollow”>..…
Buygeneric drugs…
side effects zyprexa overdose breathing autonomic…
Buyno prescription…
e-code for zometa…
Buyit now…
what is the shelf life of zyrtec…
Buynow it…
cats zanaflex…
Buydrugs without prescription…
xopenex coupon…
Buyno prescription…
zyprexa increase eps complaints…
Buyno prescription…
Zofran…
Buygeneric pills…
Zyrtec…
Buyit now…
zyprexa relprevv j-code…
Buygeneric drugs…
Rogaine…
Buyno prescription…
Synthroid…
Buygeneric pills…
Seroquel…
Buywithout prescription…
Prozac…
Buyno prescription…
Synthroid…
Buywithout prescription…
Zyprexa…
Buynow it…
Zyprexa…
Buyno prescription…
Purim…
Buyno prescription…
Rogaine…
Buygeneric meds…
Prozac…
Buygeneric meds…
Pyridium@Pyridium.Pyridium” rel=”nofollow”>……
Buygeneric meds…
Tylenol@Tylenol.Tylenol” rel=”nofollow”>……
Buygeneric meds…
Topamax@Topamax.Topamax” rel=”nofollow”>.…
Buyit now…
Prozac@Prozac.Prozac” rel=”nofollow”>……
Buynow…
Pulmicort@Pulmicort.Pulmicort” rel=”nofollow”>..…
Buyit now…
Sleep@Tea.now” rel=”nofollow”>..…
Buyno prescription…
Prozac@Prozac.Prozac” rel=”nofollow”>……
Buygeneric drugs…
Strattera@Strattera.Strattera” rel=”nofollow”>……
Buynow it…
Zoloft…
Buynow it…
Cozaar@Cozaar.Cozaar” rel=”nofollow”>.…
Buynow it…
Cialis@Cialis.Cialis” rel=”nofollow”>..…
Buyno prescription…
cms@coverage.of.pulmicort.respules.j7627” rel=”nofollow”>.…
Buygeneric pills…
dapple@hydrocortisone.cream” rel=”nofollow”>……
Buyit now…
insulin@glargine.la” rel=”nofollow”>.…
Buygeneric pills…
.…
Buynow…
buy@acai.berry.supplement” rel=”nofollow”>.…
Buyit now…
accutane@and.ototoxicity” rel=”nofollow”>……
Buyno prescription…
rhinocort@vs.beconase” rel=”nofollow”>.…
Buyno prescription…
can@cymbalta.cause.vaginal.itching.and.irritation” rel=”nofollow”>..…
Buydrugs without prescription…
advair@side.effects” rel=”nofollow”>.…
Buyit now…
.…
Buywithout prescription…
long@term.prilosec.use” rel=”nofollow”>.…
Buygeneric drugs…
.…
Buygeneric drugs…
coral@calcium.safety” rel=”nofollow”>.…
Buyit now…
abilify@and.olanzapine” rel=”nofollow”>.…
Buyit now…
pediatric@dosage.of.prednisolone” rel=”nofollow”>……
Buyno prescription…
calories@and.nutrition.in.boost.nutritional.energy.drink” rel=”nofollow”>……
Buywithout prescription…
wholesale@ginseng.root” rel=”nofollow”>……
Buyno prescription…
buy@generic.LEVITRA” rel=”nofollow”>……
Need cheap generic LEVITRA?…
Order@Cheap.Coral.Calcium” rel=”nofollow”>..…
Buygeneric pills…
Order@Discount.Coral.Calcium” rel=”nofollow”>..…
Buyno prescription…
Purchase@Cheap.Abilify” rel=”nofollow”>..…
Buynow it…
Cheap@Abilify.Online” rel=”nofollow”>..…
Buygeneric meds…
Purchase@Cheap.Acai” rel=”nofollow”>……
Buygeneric drugs…
Buy@Acai.500mg” rel=”nofollow”>.…
Buynow it…
Buy@Coral.Calcium.Online” rel=”nofollow”>.…
Buygeneric drugs…
Purchase@Cheap.Abana” rel=”nofollow”>……
Buywithout prescription…
Buy@Discount.Coral.Calcium” rel=”nofollow”>..…
Buygeneric meds…
Order@Abilify.Without.Prescription” rel=”nofollow”>..…
Buygeneric drugs…
Order@Cheap.Coral.Calcium” rel=”nofollow”>.…
Buygeneric drugs…
Buy@Cheap.Acai” rel=”nofollow”>……
Buygeneric drugs…
Purchase@Cheap.Acai” rel=”nofollow”>……
Buyit now…
Cheap@Acai.Online” rel=”nofollow”>.…
Buygeneric meds…
Purchase@Generic.Acai” rel=”nofollow”>..…
Buygeneric drugs…
Purchase@Acai.Without.Prescription” rel=”nofollow”>..…
Buyno prescription…
Order@Cheap.Accupril” rel=”nofollow”>.…
Buygeneric drugs…
Order@Discount.Accutane” rel=”nofollow”>.…
Buyno prescription…
Buy@Generic.Aciphex” rel=”nofollow”>.…
Buygeneric meds…
Cheap@Aciphex.20mg” rel=”nofollow”>.…
Buygeneric meds…
Purchase@Generic.Aciphex.20mg” rel=”nofollow”>.…
Buynow it…
Buy@Cheap.Acomplia” rel=”nofollow”>.…
Buygeneric pills…
Buy@Generic.Actonel.Without.Prescription” rel=”nofollow”>.…
Buygeneric meds…
Purchase@Generic.Actonel” rel=”nofollow”>.…
Buygeneric meds vbg…
Purchase@Actonel.Without.Prescription” rel=”nofollow”>..…
Buynow it vhx…
Actonel@35mg.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs zfk…
Buy@Actoplus.Met.Online” rel=”nofollow”>..…
Buygeneric drugs krg…
Order@Discount.Adalat” rel=”nofollow”>.…
Buygeneric meds unm…
Buy@Abilify.Online” rel=”nofollow”>..…
Buywithout prescription dyo…
Order@Discount.Abilify” rel=”nofollow”>..…
Buygeneric pills zdg…
Order@Generic.Abilify” rel=”nofollow”>.…
Buyno prescription luw…
Generic@Abilify.5mg.10mg.15mg.20mg.30mg.Without.Prescription” rel=”nofollow”>..…
Buydrugs without prescription faj…
Purchase@Acai.Online” rel=”nofollow”>.…
Buyit now ojb…
Buy@Generic.Acai.500mg” rel=”nofollow”>.…
Buygeneric drugs nih…
Buy@Cheap.Energy.Boost” rel=”nofollow”>……
Buygeneric meds svb…
Purchase@Cheap.Accupril” rel=”nofollow”>..…
Buyit now irl…
Cheap@Accutane.Online” rel=”nofollow”>.…
Buynow it lmg…
Cheap@Generic.Accutane” rel=”nofollow”>..…
Buyno prescription gdt…
Cheap@Generic.Aciphex” rel=”nofollow”>..…
Buyno prescription lka…
Cheap@Generic.Aciphex.20mg” rel=”nofollow”>……
Buynow it zdg…
Generic@Aciphex.20mg.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs itj…
Buy@Acomplia.Online” rel=”nofollow”>..…
Buyno prescription wkp…
Order@Acomplia.Online” rel=”nofollow”>.…
Buygeneric drugs axm…
Purchase@Acomplia.Online” rel=”nofollow”>..…
Buyno prescription jui…
Get@Albenza.Online” rel=”nofollow”>……
Buynow fjl…
abilify@and.weight.gain” rel=”nofollow”>……
Buyno prescription…
buy@acai.berry.juice” rel=”nofollow”>..…
Buygeneric drugs…
accutane@krupnick.class.action” rel=”nofollow”>..…
Buynow…
abilify@company.buy” rel=”nofollow”>.…
Buywithout prescription…
blue@sky.energy.solar.boost.3048” rel=”nofollow”>……
Buynow it…
phamacokinetic@of.amikacin” rel=”nofollow”>..…
Buygeneric drugs…
amoxicillin@online.buy” rel=”nofollow”>.…
Buygeneric drugs…
ampicillin@500.mg” rel=”nofollow”>.…
Buydrugs without prescription…
strong insulin…
Buy_generic meds…
methotrexate and tricyclerides side effects…
Buy_generic pills…
cancer tattoos…
Buy_without prescription…
erectile dysfunction herbal treatment…
Buy_drugs without prescription…
brown algae good for slow thyroid…
Buy_generic drugs…
novo 50 allergy medicine…
Buy_now it…
obesity children summer…
Buy_it now…
prostate cancer injection treatment…
Buy_now it…
lithium alcohol…
Buy_generic drugs…
medication for ibs…
Buy_generic drugs…
embed video webpage…
Buy_generic drugs…
effects of bulimia only sometimes…
Buy_generic meds…
what is plavix…
Buy_drugs without prescription…
postpartum remeron…
Buy_no prescription…
boniva price…
Buy_drugs without prescription…
medication errors 2nd ed…
Buy_no prescription…
australia clinical research resume…
Buy_generic drugs…
tests for assessing anxiety…
Buy_now it…
thyroid scan image…
Buy_generic pills…
oral cancer hospital…
Buy_generic meds…
joke male birth control…
Buy_generic meds…
side effects of luvox…
Buy_now…
prozac daily strength…
Buy_generic pills…
acne in cats…
Buy_it now…
tylenol without codeine related constipation…
Buy_it now…
nursing times alzheimer mavis ford…
Buy_it now…
diseaeses contracted from sand fleas…
Buy_now it…
pet ct scan results accuracy cancer…
Buy_drugs without prescription…
pictures of herpes blisters…
Buy_generic pills…
advantage of skin cancer…
Buy_generic drugs…
negative thyroid test…
Buy_no prescription…
household chemicals that kill fleas…
Buy_now it…
atkins diet first week foods…
Buy_without prescription…
fungi amazing facts…
Buy_drugs without prescription…
reversing alcohol induced neuropathy…
Buy_generic meds…
natural cures for premature ejaculation…
Buy_generic drugs…
dog hives and what causes them…
Buy_drugs without prescription…
canadian paediatric diabetes association…
Buy_now…
discovery of zinc in human health…
Buy_now…
when develop toxemia pregnancy…
Buy_it now…
emotions surviveing uterine cancer…
Buy_generic meds…
period changes leading up to menopause…
Buy_it now…
drug additiction symptoms…
Buy_generic meds…
clinical studies of clonidine…
Buy_no prescription…
diet generator reviews…
Buy_it now…
psychiatric care model…
Buy_generic meds…
new birth control pill…
Buy_now it…
most successful diet ever…
Buy_generic pills…
sleep apnea side effect of lexapro…
Buy_generic pills…
zocor orange juice effects…
Buy_no prescription…
childrens ibuprofen diabetes…
Buy_without prescription…
acute angle-closure glaucoma…
Buy_drugs without prescription…
tsa drug dogs for adoptino…
Buy_generic drugs…
regulations for dementia units…
Buy_drugs without prescription…
barbecue interactions with drugs…
Buy_generic meds…
side@effects.from.the.drug.protonix” rel=”nofollow”>……
Buynow it…
protonix@experience.buy” rel=”nofollow”>……
Buygeneric meds…
benadryl dogs…
Buy_generic drugs…