symbol to proc
📝 RubyConverts a symbol into a proc that calls the corresponding method on each element, enabling concise iteration like array.map(&:method).
Ruby
# Symbol to proc: converts a symbol into a proc that calls the method on its argument
words = ["apple", "banana", "cherry"]
lengths = words.map(&:length)
upcased = words.map(&:upcase)
puts "Lengths: #{lengths}"
puts "Uppercase: #{upcased}"
Comments
No comments yet. Start the discussion.