Sha256: d4819f1b9214fe285f452a50c27c0d768326c9b0dcd45c78c90bb7d77339868a
Contents?: true
Size: 1.19 KB
Versions: 22
Compression:
Stored size: 1.19 KB
Contents
class Array def args flatten.map{|a| a.args}.flatten end def last_option default = self.last_arg last = self.flatten.last last.kind_of?(Hash) ? last : default end def last_arg default = {} last = self.flatten.last last.kind_of?(Hash) ? last : default end def last_arg_value default = nil last = self.flatten.last raise ArgumentError, "Default value must be a Hash, was #{default}" if !default.kind_of? Hash key = default.keys.first return default[key] if !last.kind_of? Hash last[key] ? last[key] : default[key] end end class Symbol def args [to_s] end end class String def args (self =~ /\w+\s+\w+/) ? self.split : self end end def last_option *args default = last_arg({}, *args) last = args.flatten.last last.kind_of?(Hash) ? last : default end def last_arg default, *args last = args.flatten.last last.kind_of?(Hash) ? last : default end def last_arg_value default, *args last = args.flatten.last raise ArgumentError, "Default value must be a Hash, was #{default}" if !default.kind_of? Hash key = default.keys.first return default[key] if !last.kind_of? Hash last[key] ? last[key] : default[key] end
Version data entries
22 entries across 22 versions & 1 rubygems