Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The language is ruby.

    array.map(&:to_s)
eventually means

    array.map{|str| str.to_s }
As I understand it, the & means convert a variable to a code block. If the object already is a callable object (proc or lambda) ruby doesn't need to do anything to pass it through. Symbols (:to_s) aren't callable so ruby calls the to_proc method on it. The rails framework addd this for Ruby 1.8. The code is below.

    # File activesupport/lib/active_support/core_ext/symbol.rb, line 10
    def to_proc
      Proc.new { |*args| args.shift.__send__(self, *args) }
    end


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: