summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxim Filimonov <tpaktopsp@gmail.com>2013-07-21 15:24:52 +1000
committerMaxim Filimonov <tpaktopsp@gmail.com>2013-07-21 15:24:52 +1000
commitbde56b72375dfbd6198dfdfa2fc7e2f86d50ba11 (patch)
tree50e3ef1f61ea9aaa18e3b268b0c653e7872fb390 /lib
parent3321005d0bd77e0811a2cea6dbbd302d8e86851f (diff)
downloadhashie-bde56b72375dfbd6198dfdfa2fc7e2f86d50ba11.tar.gz
Do not respond to suffixes for keys which are not present in mash. Fixes compability with activesupport permit?
Diffstat (limited to 'lib')
-rw-r--r--lib/hashie/mash.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb
index 880225e..84830c1 100644
--- a/lib/hashie/mash.rb
+++ b/lib/hashie/mash.rb
@@ -55,6 +55,7 @@ module Hashie
# mash.author # => <Mash>
#
class Mash < Hash
+ ALLOWED_SUFFIXES = %w(? ! = _)
include Hashie::PrettyInspect
alias_method :to_s, :inspect
@@ -187,10 +188,16 @@ module Hashie
# Will return true if the Mash has had a key
# set in addition to normal respond_to? functionality.
def respond_to?(method_name, include_private=false)
- return true if key?(method_name) || method_name.to_s.slice(/[=?!_]\Z/)
+ return true if key?(method_name) || prefix_method?(method_name)
super
end
+
+ def prefix_method?(method_name)
+ method_name = method_name.to_s
+ method_name.end_with?(*ALLOWED_SUFFIXES) && key?(method_name.chop)
+ end
+
def method_missing(method_name, *args, &blk)
return self.[](method_name, &blk) if key?(method_name)
match = method_name.to_s.match(/(.*?)([?=!_]?)$/)