Advertisement
saasbook

method_missing_example.rb

Jan 10th, 2012
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.21 KB | None | 0 0
  1. class Fixnum
  2.   def method_missing(method_id, *args)
  3.     name = method_id.to_s
  4.     if name =~ /^second|minute|hour$/
  5.       self.send(name + 's')
  6.     else
  7.       super # pass the buck to superclass
  8.     end
  9.   end
  10. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement