Method: Sequel::Dataset#map
- Defined in:
- lib/sequel/dataset/actions.rb
#map(column = nil, &block) ⇒ Object
Maps column values for each record in the dataset (if a column name is given), or performs the stock mapping functionality of Enumerable otherwise. Raises an Error if both an argument and block are given.
DB[:table].map(:id) # SELECT * FROM table
# => [1, 2, 3, ...]
DB[:table].map{|r| r[:id] * 2} # SELECT * FROM table
# => [2, 4, 6, ...]
337 338 339 340 341 342 343 344 |
# File 'lib/sequel/dataset/actions.rb', line 337 def map(column=nil, &block) if column raise(Error, ARG_BLOCK_ERROR_MSG) if block super(){|r| r[column]} else super(&block) end end |