[Ruby]mapメソッドの省略記法
Rubyのmapメソッドとは|基本的なmapの記述方法と省略記法|フリエン
map { |x| x.chomp }は、map(&:chomp)と省略することができる。省略記法を利用した場合は、全ての要素に対して&の後にシンボルで指定したメソッドが繰り返し実行され、結果が配列として返ってくる。
conn = Faraday.new(url: 'https://www.google.com/finance/getprices') do |builder|
builder.request :url_encoded
builder.adapter :net_http
end
response = conn.get do |req|
req.params = params
end
lines = response.body.each_line.map(&:chomp)Related contents
TECH
2017.06.24
TECH
2016.06.05
TECH
2016.02.10
TECH
2015.03.27
TECH
2014.12.13
TECH
2013.05.29
TECH
2013.05.18
TECH
2012.04.19