Commits

Claudio Lassala  committed eb0cbf7

started to implement method_missing

  • Participants
  • Parent commits 4c33e7f

Comments (0)

Files changed (3)

File Dynamic/ruby_dynamic/Gemfile.lock

     rspec-mocks (2.7.0)
 
 PLATFORMS
+  ruby
   x86-mingw32
 
 DEPENDENCIES

File Dynamic/ruby_dynamic/customer.rb

 
 class DynamicEntity
 
+  attr_reader :additional_data
+
   def initialize(additional_data)
+      @additional_data = additional_data
   end
   
-  def method_missing()
+  def method_missing(name, *args)
+
+      if name =~ /=$/
+        self.additional_data[name.to_s.gsub("=", "")] = args[0]
+      else
+        self.additional_data[name] 
+      end
+  end
+
+  def respond_to(name)
+    raise self.additional_data.inspect
+    self.additional_data.include?(name)
   end
 end
 
 class Customer < DynamicEntity
     attr_accessor :first_name, :list_name
+
 end

File Dynamic/ruby_dynamic/spec/customer_spec.rb

-require 'customer'
+require './customer'
 
 describe Customer do
 
       context "Given additional dynamic data for a customer" do
       
         before(:each) do
-            additional_data = { :comments => "Some comments...",
-                                :number_of_dependents => 3 }
+            @additional_data = { :comments => "Some comments...",
+                                 :number_of_dependents => 3 }
         end
       
         describe "When object is constructed" do
           
-          let(:customer) { Customer.new } 
+          let(:customer) { Customer.new(@additional_data) } 
 
           it "should expose the additional properties" do
               customer.should respond_to(:comments)
         end
       end
    end
-end
+end