My wife and I celebrate our 3 year anniversary today. Cards are cheap, and programming is fun.

While this may seem like a lot of code to tell my wife Happy Anniversary, it is re-usable for many years to come. This is what happens when it gets late. Code for her to run in her terminal.

anniversary.rb

  1. class Fixnum
  2. def wonderful
  3. "#{self.to_s} wonderful"
  4. end
  5. end
  6.  
  7. class String
  8. def years_of_marriage
  9. "#{self} years of marriage"
  10. end
  11. end
  12.  
  13. module Wedding
  14. def location
  15. "on a #{self.conditions} beach in #{self.city}, #{self.state}"
  16. end
  17.  
  18. def city
  19. "Cambria"
  20. end
  21.  
  22. def state
  23. "California"
  24. end
  25.  
  26. def date
  27. Time.utc(2005, 06, 05)
  28. end
  29.  
  30. def formatted_date
  31. self.date.strftime("%A, %B %d, %Y")
  32. end
  33.  
  34. def conditions
  35. "cold and windy"
  36. end
  37. end
  38.  
  39. class Wife
  40. attr_accessor :name
  41. include Wedding
  42.  
  43. def initialize(name)
  44. self.name = name
  45. end
  46.  
  47. def +(msg)
  48. return "Dear #{self.name}, on #{self.formatted_date} we got married #{self.location}. Thank you for #{msg}. Happy Anniversary, I love you."
  49. end
  50. end
  51.  
  52. puts Wife.new('Tessa') + 3.wonderful.years_of_marriage

Which gives us (drumroll, please):

anniversary.rb

  1. Dear Tessa, on Sunday, June 05, 2005 we got married on a cold and windy beach in Cambria, California. Thank you for 3 wonderful years of marriage. Happy Anniversary, I love you.
  2. => nil

8 Comments Add your comment

  1. eric June 5th, 2008

    Happy Anniversary. :)

  2. Brad Dielman June 5th, 2008

    Happy anniversary, Nate!

  3. Joe F. June 5th, 2008

    Happy Anniversery, geek! :P

  4. Josh Walsh June 5th, 2008

    I feel so happy for you guys, and I pity your wife for putting up with cheezy moves like this one.

    Congrats my friend.

  5. Dana Kashubeck June 5th, 2008

    Happy anniversary!!!

  6. Geof Harries June 5th, 2008

    Happy anniversary, Tessa and Nate. I think this would look great on a t-shirt.

  7. brendan cullen June 5th, 2008

    Should we all pitch in and register isitnateandtessasanniversary.com, so this code has a proper home?

  8. Chris Hattery June 27th, 2008

    I liked this site when it had more... content. It needs more content. And more frequent content. Content on a daily rotation.

Comments are closed.