Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Hash
- # Aggregates all one-key hashes, or a single multi-key hash from an
- # Enumerable. Use for getting options out of an *arguments array.
- def self.opts_from args, *opts
- opts = Hash.opts_from opts # recursive! yay!
- raise ArgumentError if !args.is_a? Enumerable
- orig_args = args.clone
- all_hashes = args.select {|arg| arg.is_a? Hash }
- if opts[:destructive]
- if all_hashes.size == 1
- else # all_hashes.size
- end # all_hashes.size
- else # opts[:destructive]
- if all_hashes.size == 1
- else # all_hashes.size
- end # all_hashes.size
- end # opts[:destructive]
- else
- hash_args = args.select {|arg| arg.is_a? Hash && arg.size == 1 }
- end
- hash_args
- end
- # Aggregates all one-key hashes, or a single multi-key hash from an
- # Enumerable, removing these from the original Enum. Use for getting options
- # out of an *arguments array.
- def self.opts_from! args, *opts
- Hash.opts_from args, {:destructive => true}, opts
- end
- end
Add Comment
Please, Sign In to add comment