Guest User

Untitled

a guest
May 7th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. require 'delegate'
  2.  
  3. module Associate
  4. def associate(obj, *args)
  5. raise "Not a hash" if args[0] and !args[0].kind_of?(Hash)
  6. class << obj
  7. attr_accessor :__associated
  8. end
  9.  
  10. obj.__associated = args[0]
  11.  
  12. return obj
  13. end
  14.  
  15. module_function :associate
  16. end
  17.  
  18. if __FILE__ == $0
  19. include Associate
  20.  
  21. pr = associate([], { :one => 1 })
  22.  
  23. case pr
  24. when Array
  25. p true
  26. else
  27. p false
  28. end
  29.  
  30. p pr.__associated[:one]
  31. end
Add Comment
Please, Sign In to add comment