Monday 13 June 2016

method_missing: A VCR and Using the VCR


Hi Readers,

Today we are going to take an example class VCR and verify the method_missing concept.

method_missing: A VCR

    class VCR 
      def initialize 
        @messages = [] 
      end 
     
      def method_missing(method, *args, &block) 
        @messages << [method, args, block] 
      end 
     
      def play_back_to(obj) 
        @messages.each do |method, args, block| 
          obj.send(method, *args, &block) 
        end 
      end 
    end

Using the VCR:

    require 'vcr' 
     
    vcr = VCR.new 
    vcr.gsub! /Ruby/, "Crazy" 
    vcr.upcase! 
    object = "I Go Ruby" 
    vcr.play_back_to(object) 
    puts object  


Just practice this example , i will get back to you with new concept.

Thanks for reading, subscribe this blog to get more updates.

No comments:

Post a Comment

My Experience in RUBYCONF INDIA 2016

Hi Readers, Rubyconf India is a global event complementing other RubyConf events across the world. I attended this event held on 19-20 ma...