Sha256: 82bb9e3803cea84d7a5e3e9218129afbb9a34bdef0b1f1694f674b5fbd3439b4

Contents?: true

Size: 457 Bytes

Versions: 5

Compression:

Stored size: 457 Bytes

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.
class Symbol

  # the well-known #to_proc
  # creates a lambda that sends the symbol and any further arguments
  # to the object yielded.
  #   [1, 2, 3].map(&:to_s)    # => ['1', '2', '3']
  #   %w[a b c].map(&:to_sym)  # => [:a, :b, :c]

  def to_proc
    lambda{|o, *args| o.send(self, *args) }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ramaze-0.0.8 lib/ramaze/snippets/symbol/to_proc.rb
ramaze-0.0.6 lib/ramaze/snippets/symbol/to_proc.rb
ramaze-0.0.7 lib/ramaze/snippets/symbol/to_proc.rb
ramaze-0.0.9 lib/ramaze/snippets/symbol/to_proc.rb
ramaze-0.1.0 lib/ramaze/snippets/symbol/to_proc.rb