diff options
author | Ben Schwarz <ben.schwarz@gmail.com> | 2010-01-14 10:24:58 +0800 |
---|---|---|
committer | Michael Bleigh <michael@intridea.com> | 2010-01-15 01:13:53 +0800 |
commit | 81ec5006cfe2d4c0adc7cecf9940eb6dbb8cbe39 (patch) | |
tree | be237f4f01eb89f2d0c88b218154591e21e790f9 /lib/hashie/dash.rb | |
parent | a2ecc494e21934af553a5141be1c89e1e9e5558f (diff) | |
download | hashie-81ec5006cfe2d4c0adc7cecf9940eb6dbb8cbe39.tar.gz |
Swapped out class variables to scale the ancestors tree. This allows for the super class to not receive properties set on subclasses.
Diffstat (limited to 'lib/hashie/dash.rb')
-rw-r--r-- | lib/hashie/dash.rb | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb index 3d73090..6d4e6b5 100644 --- a/lib/hashie/dash.rb +++ b/lib/hashie/dash.rb @@ -26,8 +26,8 @@ module Hashie def self.property(property_name, options = {}) property_name = property_name.to_sym - (@@properties ||= []) << property_name - (@@defaults ||= {})[property_name] = options.delete(:default) + (@properties ||= []) << property_name + (@defaults ||= {})[property_name] = options.delete(:default) class_eval <<-RUBY def #{property_name} @@ -43,7 +43,14 @@ module Hashie # Get a String array of the currently defined # properties on this Dash. def self.properties - @@properties.collect{|p| p.to_s} + properties = [] + ancestors.each do |elder| + if elder.instance_variable_defined?("@properties") + properties << elder.instance_variable_get("@properties") + end + end + + properties.flatten.map{|p| p.to_s} end # Check to see if the specified property has already been @@ -54,7 +61,14 @@ module Hashie # The default values that have been set for this Dash def self.defaults - @@defaults + properties = {} + ancestors.each do |elder| + if elder.instance_variable_defined?("@defaults") + properties.merge! elder.instance_variable_get("@defaults") + end + end + + properties end # You may initialize a Dash with an attributes hash |