lib/configoro/hash.rb in configoro-1.0.0 vs lib/configoro/hash.rb in configoro-1.1.0
- old
+ new
@@ -77,10 +77,16 @@
if args.empty? then
create_getter meth
else
raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
end
+ elsif meth.to_s =~ /^(.+)\?$/ and include?(root_meth = $1) then
+ if args.empty? then
+ !! create_getter(root_meth) #TODO duplication of logic
+ else
+ raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
+ end
else
super
end
end
@@ -115,16 +121,28 @@
self[meth.to_s]
else
remove_getter meth
end
end
-
+
+ singleton_class.send(:define_method, :"#{meth}?") do
+ if include?(meth.to_s) then
+ !! self[meth.to_s]
+ else
+ remove_getter meth
+ end
+ end
+
self[meth.to_s]
end
def remove_getter(meth)
if methods.include?(meth.to_sym) then
instance_eval "undef #{meth.to_sym.inspect}"
+ end
+
+ if methods.include?(:"#{meth}?") then
+ instance_eval "undef #{:"#{meth}?".inspect}"
end
raise NameError, "undefined local variable or method `#{meth}' for #{self.inspect}"
end
end