Commits

claudiolassala committed eb0cbf7

started to implement method_missing

Comments (0)

Files changed (3)

Dynamic/ruby_dynamic/Gemfile.lock

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

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

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.