ruby - Insert information from hash into iteration -


i trying insert information hash monthly_multipliers iterator.

month_multipliers = { april: 1, may: 2, june: 3, july: 4, august: 5, september: 6, october: 7, november: 8, december: 9, january: 10, february: 11, march: 12} months = ['april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december', 'january', 'february', 'march'] 

i iterate through each month, , need inject monthly multiplier each month, june 3 august 5 etc.

months.each |month|   instance_variable_set :"@#{month}_income", (monthly_new_account_income * month_multipliers[month]) + previous_years_monthly_income end 

this bit doesn't work

 month_multipliers[month]) 

i tried sending , getting instance variable, cannot format right.

month_multipliers has keys in symbol objects, months has keys string objects. use either symbol or string objects or convert keys correct object before retrieving values hash.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -