summaryrefslogtreecommitdiff
path: root/lib/hashie/dash.rb
diff options
context:
space:
mode:
authorAndré Luis Leal Cardoso Junior <andrehjr@gmail.com>2009-11-16 00:53:33 -0200
committerAndré Luis Leal Cardoso Junior <andrehjr@gmail.com>2009-11-16 00:53:33 -0200
commitbb4feb07579ad86d2892fe0a6f5bc4dfa7b19303 (patch)
treeb75ba86a5323dca07578a16b8749dfb6ec3b049d /lib/hashie/dash.rb
parentf20d0ac3969a5679c57434b734e4725490ce249a (diff)
downloadhashie-bb4feb07579ad86d2892fe0a6f5bc4dfa7b19303.tar.gz
Dashes now raises NoMethodError when reading a non-existent property
Diffstat (limited to 'lib/hashie/dash.rb')
-rw-r--r--lib/hashie/dash.rb20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb
index eac2293..47b0afe 100644
--- a/lib/hashie/dash.rb
+++ b/lib/hashie/dash.rb
@@ -71,18 +71,24 @@ module Hashie
# Retrieve a value from the Dash (will return the
# property's default value if it hasn't been set).
- def [](property_name)
- super(property_name.to_sym)
+ def [](property)
+ super(property.to_sym) if property_exists? property
end
# Set a value on the Dash in a Hash-like way. Only works
# on pre-existing properties.
def []=(property, value)
- if self.class.property?(property.to_sym)
- super
- else
- raise NoMethodError, "The property '#{property}' is not defined for this Dash."
- end
+ super if property_exists? property
end
+
+ private
+ # Raises an NoMethodError if the property doesn't exist
+ #
+ def property_exists?(property)
+ unless self.class.property?(property.to_sym)
+ raise NoMethodError, "The property '#{property}' is not defined for this Dash."
+ end
+ true
+ end
end
end