diff options
author | Xabier de Zuazo <xabier@onddo.com> | 2014-12-01 22:42:41 +0100 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-27 12:02:43 -0800 |
commit | bbecbb9b550d0ad9daaebbfc04fb6e3ce919731a (patch) | |
tree | 945435cb200fb8f02b219c7705496ce21295207e /lib | |
parent | a754971ef57ab776ba8c49fc326b42f13a2bc84b (diff) | |
download | chef-bbecbb9b550d0ad9daaebbfc04fb6e3ce919731a.tar.gz |
Use default argument values for #define_method and avoid exceptions (ruby < 2 specific, issue #2497)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/mixin/securable.rb | 5 | ||||
-rw-r--r-- | lib/chef/resource/lwrp_base.rb | 5 |
2 files changed, 3 insertions, 7 deletions
diff --git a/lib/chef/mixin/securable.rb b/lib/chef/mixin/securable.rb index 683012cde8..aaedf0b9ba 100644 --- a/lib/chef/mixin/securable.rb +++ b/lib/chef/mixin/securable.rb @@ -111,10 +111,7 @@ class Chef # equivalent to something like: # def rights(permissions=nil, principals=nil, args_hash=nil) - define_method(name) do |*args| - raise ArgumentError.new("wrong number of arguments (#{args.length} for 3)") if args.length >= 4 - permissions, principals, args_hash = args - + define_method(name) do |permissions=nil, principals=nil, args_hash=nil| rights = self.instance_variable_get("@#{name.to_s}".to_sym) unless permissions.nil? input = { diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb index f5965d0ee5..0a1253780c 100644 --- a/lib/chef/resource/lwrp_base.rb +++ b/lib/chef/resource/lwrp_base.rb @@ -73,9 +73,8 @@ class Chef # Define an attribute on this resource, including optional validation # parameters. def self.attribute(attr_name, validation_opts={}) - define_method(attr_name) do |*args| - raise ArgumentError.new("wrong number of arguments (#{args.length} for 0 or 1)") if args.length > 1 - set_or_return(attr_name.to_sym, args.first, validation_opts) + define_method(attr_name) do |arg=nil| + set_or_return(attr_name.to_sym, arg, validation_opts) end end |