select

sdbm.select { |key, value| ... } รข Array
Instance Public methods

Returns a new Array of key-value pairs for which the block returns true.

Example:

require 'sdbm'

SDBM.open 'my_database' do |db|
  db['apple'] = 'fruit'
  db['pear'] = 'fruit'
  db['spinach'] = 'vegetable'

  veggies = db.select do |key, value|
    value == 'vegetable'
  end #=> [["apple", "fruit"], ["pear", "fruit"]]
end
doc_ruby_on_rails
2015-05-14 04:38:14
Comments
Leave a Comment

Please login to continue.