/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
- class Class
- # Convert instatiation of a class into a Proc.
- #
- # class Person
- # def initialize(name)
- # @name = name
- # end
- #
- # def inspect
- # @name.to_str
- # end
- # end
- #
- # %w(john bob jane hans).map(&Person) => [john, bob, jane, hans]
- #
- # CREDIT: Daniel Schierbeck
- def to_proc
- proc{|*args| new(*args)}
- end
- end
- =begin test
- reqiure 'test/unit'
- class TestClassConversion < Test::Unit::TestCase
- Person = Struct.new(:name)
- def test_to_proc
- people = ["joe"].map(&Person)
- assert_equal("joe", people[0].name)
- end
- end
- =end