Skip to content
This repository
Browse code

Fix DynamicStruct on 1.8.

  • Loading branch information...
commit be64cbfef760a8e0eb6a0e71c055124f825d29a3 1 parent 5b62351
Myron Marston authored October 19, 2012
8  lib/interpol/dynamic_struct.rb
@@ -25,10 +25,16 @@ def self.recursively_freeze(object)
25 25
         when Array
26 26
           object.each { |obj| recursively_freeze(obj) }
27 27
         when Hash
28  
-          object.default_proc = DEFAULT_PROC
  28
+          set_default_proc_on(object)
29 29
           recursively_freeze(object.values)
30 30
       end
31 31
     end
  32
+
  33
+    def self.set_default_proc_on(hash)
  34
+      hash.default_proc = DEFAULT_PROC
  35
+    end
32 36
   end
33 37
 end
34 38
 
  39
+require 'interpol/hash_set_default_proc_18' unless {}.respond_to?(:default_proc=)
  40
+
9  lib/interpol/hash_set_default_proc_18.rb
... ...
@@ -0,0 +1,9 @@
  1
+module Interpol
  2
+  module DynamicStruct
  3
+    # Hash#default_proc= isn't defined on 1.8; this is the best we can do.
  4
+    def self.set_default_proc_on(hash)
  5
+      hash.replace(Hash.new(&DEFAULT_PROC).merge(hash))
  6
+    end
  7
+  end
  8
+end
  9
+

0 notes on commit be64cbf

Please sign in to comment.
Something went wrong with that request. Please try again.