Easy to use array.map (&: method)

Easy to use array.map (&: method)

Example

Suppose you have the following formula. Convert each element to uppercase in the block and store it in an array.

['a', 'b', 'c'].map{|s| s.upcase } #=> ["A", "B", "C"]

Easy to use array.map (&: method)

You can easily follow the above example using array.map (&: method).

['a', 'b', 'c'].map(&:upcase) # => ["A", "B", "C"]

Applicable condition

  1. Only one block argument
  2. The method you call inside the block has no arguments
  3. Inside the block, there is no processing other than calling the method for the block argument

Recommended Posts

Easy to use array.map (&: method)
How to use the link_to method
How to use the include? method
How to use the form_with method
Function is very easy to use
[Java] How to use join method
[Ruby] How to use any? Method
Easy to use Cloud Firestore (Android)
How to use Ruby inject method
How to use submit method (Java Silver)
Method to search
[Rails] How to use the map method
[Java] How to use the toString () method
[Rails] How to use helper method, confimartion
[Ruby] How to use gsub method and sub method
When you want to use the method outside
Output of how to use the slice method
How to use the replace () method (Java Silver)
[Ruby on Rails] How to use session method
[Ruby basics] How to use the slice method
How to use Map
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
PATH to use docker-slim
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use TreeSet
[How to use label]
How to use hashes
How to use JUnit 5
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
16 Corresponds to method invocation
How to use Map
Easy to maintain FizzBuzz
[Java] How to use compareTo method of Date class
[rails] How to use devise helper method before_action: authenticate_user!
How to use the getter / setter method (in object orientation)
How to use Chain API
[Java] How to use Map
How to use Priority Queuing
[Rails] How to use enum
Easy to create Processing library
How to use java Optional
How to use JUnit (beginner)
How to use Ruby return
[Rails] How to use enum
Easy way to check method / field list in Java REPL
How to use @Builder (Lombok)
[Swift] How to use UserDefaults
How to use java class
How to use Swift UIScrollView
How to use Big Decimal
How to use String [] args
[Java] How to use string.format
How to use rails join