Isn’t it great when you try to track down the source of an error and find it in some code you wrote… while you were apparently on CRAZY PILLS?

Here’s something I just found this morning. Maybe I need another cup of coffee (as it’s not even 9am yet), but… wtf??

   1  def create_thread(user, contacts, params)
2 mail_thread = Mail.new
3 mail_thread.attributes = valid_mail_params(params)
4 # ...
5 end
6 def assign_mail_params(valid_params, k,v)
7 valid_params[k] = v if self.attributes.keys.include? k
8 end
9
10 def valid_mail_params(params, valid_params = {})
11 params.each_pair do |k,v|
12 (v.is_a? Hash) ? valid_mail_params(v, valid_params) : assign_mail_params(valid_params, k, v)
13 end
14 valid_params
15 end
16
17 def self.valid_mail_params(params, valid_params = {})
18 self.new.valid_mail_params(params, valid_params = {})
19 end


I’m going to guess I was trying to ensure that params unrelated to the object were not getting assigned as attributes (thus causing errors…) but, still, that’s insane. Time to refactor, after this next cup of coffee :)

Tags: refactor, ruby, wtf
Hierarchy: previous, next

Comments

There are 2 comments on this post. Post yours →

Hi Jacqui,

This is Mike, a recruiter with CTI TEKSOURCE. I just took a look over your profile and have some opportunities that we should definitely discuss. Its with my client here in NYC and they are looking for either PHP or RoR developers. This is a large music entertainment company and the work will concern delivering content to mobile devices and their online music storefront. Please give me a call to discuss this. If your not looking please let me know if you have any friends or former colleagues I can contact…We will do cash referrals for the lead and confidentiality is guaranteed. Thanks and looking forward to hearing from you!

Here are the specs…

• Server side web development
• Focus on delivery of content to mobile devices
• Participate in all phases of the development cycle
• Communicate with business partners including mobile providers, social networks, and media services in regards to developing new technologies
• Extend and manage a highly dynamic distributed computing environment used to power direct-to-consumer applications

Job requirements:
Education and/or Experience:

Required
• Server side web development
• Degree in CS/EE or related
• Excellent problem solving and communication

Additional Desired Skills
• ActionScript/Flash development experience
• Experience with digital music and metadata
• Experience with XSL
• Expertise with data models and SQL
• Experience with MySql
• Knowledge of Linux servers
• Knowledge of mobile content delivery
• Rudimentary digital signal processing
• Love of music are added pluses

OR

Linux Web Server Administrator with LAMP STACK Experience

*** Ideal candidate will have a development background using PHP and / or Java whether in real world job experience or in college. Training will be provided to support PHP enterprise-wide digital content applications ***

Competitive Base Salary with excellent Benefits Package with a Global Music and Entertainment Company

Responsible for automated installation, configuration, content management and deployment programs, programmed enhancements, and maintained main product line for Content Management Systems

Maintenance and development environment primarily uses custom built Linux+Apache+MySQL+PHP (LAMP), Javascript and XML (AJAX), OSS applications and shell scripts.

Maintain Linux Web Server environment ensuring uptime, load balancing, security measures , and monitoring. Responsible for multiple Linux Systems, including firewalls/gateways, LAMP systems, and VMWare application servers.

Sincerely,

Mike Marc-Aurele
Senior Resource Manager
CTI TEKSOURCE LLC
45 West 21st Street
4th Floor
New York, New York 10010
212 453-9009 Direct
973 557-5386 Mobile
212 453-9010 MAIN
212 453-9011 FAX
Mmaurele@CTITEKSource.com

I was going to comment that you probably needed just another cup and then I saw the comment above. I think that woke me up when I just started to laugh and can’t stop from laughing because a recruiter is stalking you. haaaay.

Post a comment

Required fields in bold.