Guest User

Untitled

a guest
Apr 26th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. class Hash
  2.  
  3. # Aggregates all one-key hashes, or a single multi-key hash from an
  4. # Enumerable. Use for getting options out of an *arguments array.
  5. def self.opts_from args, *opts
  6. opts = Hash.opts_from opts # recursive! yay!
  7. raise ArgumentError if !args.is_a? Enumerable
  8. orig_args = args.clone
  9.  
  10. all_hashes = args.select {|arg| arg.is_a? Hash }
  11.  
  12. if opts[:destructive]
  13. if all_hashes.size == 1
  14.  
  15. else # all_hashes.size
  16.  
  17. end # all_hashes.size
  18. else # opts[:destructive]
  19. if all_hashes.size == 1
  20.  
  21. else # all_hashes.size
  22.  
  23. end # all_hashes.size
  24. end # opts[:destructive]
  25.  
  26.  
  27. else
  28. hash_args = args.select {|arg| arg.is_a? Hash && arg.size == 1 }
  29. end
  30. hash_args
  31. end
  32.  
  33. # Aggregates all one-key hashes, or a single multi-key hash from an
  34. # Enumerable, removing these from the original Enum. Use for getting options
  35. # out of an *arguments array.
  36. def self.opts_from! args, *opts
  37. Hash.opts_from args, {:destructive => true}, opts
  38. end
  39. end
Add Comment
Please, Sign In to add comment