PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/lib/core/facets/class/to_proc.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 42 lines | 5 code | 7 blank | 30 comment | 0 complexity | 911c9f75d7e0e53bfca1c5f0f47813df MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. class Class
  2. # Convert instatiation of a class into a Proc.
  3. #
  4. # class Person
  5. # def initialize(name)
  6. # @name = name
  7. # end
  8. #
  9. # def inspect
  10. # @name.to_str
  11. # end
  12. # end
  13. #
  14. # %w(john bob jane hans).map(&Person) => [john, bob, jane, hans]
  15. #
  16. # CREDIT: Daniel Schierbeck
  17. def to_proc
  18. proc{|*args| new(*args)}
  19. end
  20. end
  21. =begin test
  22. reqiure 'test/unit'
  23. class TestClassConversion < Test::Unit::TestCase
  24. Person = Struct.new(:name)
  25. def test_to_proc
  26. people = ["joe"].map(&Person)
  27. assert_equal("joe", people[0].name)
  28. end
  29. end
  30. =end