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

Language Ruby Lines 43
MD5 Hash 911c9f75d7e0e53bfca1c5f0f47813df Estimated Cost $329 (why?)
Repository https://bitbucket.org/mediashelf/fedora-migrator View Raw File
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
Back to Top