30 Jul '12, 1pm

Always define respond_to_missing? when overriding method_missing

July 30, 2012 Tagged: method_missing ruby respond_to_missing? Comments (View) Always define respond_to_missing? when overriding method_missing method_missing is still considered scary, but here’s something more scary: forgetting to override respond_to? . Whoa, right? Just gave you an anxiety attack there. How about #method , though? Does that still work? Go ahead, try it. Here, I’ll try it with you: require 'ostruct' class Order def user @_user ||= OpenStruct.new(name: 'Mike', age: 28, occupation: 'slacker') end def method_missing(method_name, *arguments, &block) if method_name.to_s =~ /user_(.*)/ user.send($1, *arguments, &block) else super end end def respond_to?(method_name, include_private = false) method_name.to_s.start_with?('user_') || super end end OK now I’ll load that into irb and play with it: ruby-1.9.2-p290> order = Order.new => #<Order:0x00000001e40948> ruby-...

Full article: http://robots.thoughtbot.com/post/28335346416/always-defi...

Tweets

quick post!

quick post!

fourfeetnine.com 12 Aug '12, 9am

I’ve wanted to write this post for some time but got too caught up with the wedding! More than a month ago I wrote this po...

vaio promotion if anybody interested

vaio promotion if anybody interested

courts.com.sg 31 Jul '12, 12pm

The Sony SVE15117FGB 15.5in Intel Core i5-2450M Notebook is from the latest VAIO E series. Enjoy loud and clear sounds wit...

Olivia Wilde: Veganism ‘Not Always Easy’

Olivia Wilde: Veganism ‘Not Always Easy’

ecorazzi.com 31 Jul '12, 8pm

Olivia Wilde: Veganism ‘Not Always Easy’ 0 Tweet by China DeSpain Freeman July 31, 2012 Categories: Eats , Vegan , Vegetar...

Ruby5 Episode #293: ActiveRecord, Rails Streami...

ruby5.envylabs.com 31 Jul '12, 3pm

July 27th, 2012 New Rails, how to ride a mountain lion (grrrr), tell don't ask, enums get classy, kickstarting your backen...

@cupakromer Here's the article I was referencin...

blog.jayfields.com 05 Aug '12, 3pm

I love the value that method_missing provides; unfortunately, sometimes I get into trouble when I abuse the power Matz has...

Women Sandals are always a hot item so start yo...

cax.com 05 Aug '12, 7pm

Partager WomenSandals.org ... $499 5 months old domain listed by the owner Private seller (portfolio )