Hi Readers,
Today we are going to take an example class VCR and verify the method_missing concept.
method_missing: A VCR
class VCRdef 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
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