summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Schwarz <ben.schwarz@gmail.com>2010-01-14 06:59:43 +0800
committerMichael Bleigh <michael@intridea.com>2010-01-14 07:14:09 +0800
commit0552fc42953b7505c1a848d8861e7ac7d0c25653 (patch)
tree25674624007f94f58dd952cc54fbf62a44161fa4
parent3b4d730745dae8a8bf3751348d9aa650efd2d317 (diff)
downloadhashie-0552fc42953b7505c1a848d8861e7ac7d0c25653.tar.gz
Storing dash properties in a class variable to allow for subclassing (#Issue 2)
-rw-r--r--lib/hashie/dash.rb8
-rw-r--r--spec/hashie/dash_spec.rb13
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb
index 47b0afe..3d73090 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,7 @@ module Hashie
# Get a String array of the currently defined
# properties on this Dash.
def self.properties
- @properties.collect{|p| p.to_s}
+ @@properties.collect{|p| p.to_s}
end
# Check to see if the specified property has already been
@@ -54,7 +54,7 @@ module Hashie
# The default values that have been set for this Dash
def self.defaults
- @defaults
+ @@defaults
end
# You may initialize a Dash with an attributes hash
diff --git a/spec/hashie/dash_spec.rb b/spec/hashie/dash_spec.rb
index 9443ef6..df27fe7 100644
--- a/spec/hashie/dash_spec.rb
+++ b/spec/hashie/dash_spec.rb
@@ -6,6 +6,9 @@ class DashTest < Hashie::Dash
property :count, :default => 0
end
+class Subclassed < DashTest
+end
+
describe Hashie::Dash do
it 'should be a subclass of Hashie::Hash' do
(Hashie::Dash < Hash).should be_true
@@ -77,4 +80,14 @@ describe Hashie::Dash do
DashTest.new.defaulted.should == 'abc'
end
end
+end
+
+describe Subclassed do
+ it "should inherit all properties from DashTest" do
+ Subclassed.properties.size.should == 5
+ end
+
+ it "should init without raising" do
+ lambda { Subclassed.new }.should_not raise_error
+ end
end \ No newline at end of file