Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

memory_storage

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memory_storage

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

MemoryStorage

A very simple in memory storage utility class.

Installation

Add the gem to your Gemfile

gem 'memory_storage'

Usage

The only requirement to store objects with MemoryStorage is that persistent objects must respond to #id

Examples:

class Item
  attr_accessor :id, :name, :amount

  def initialize(id, name, amount)
    @id = id
    @name = name
    @amount = amount
  end
end

item = Item.new(1, 'Item one', 10)

# saving an object
MemoryStorage.save(item)

# retrieving object by id
MemoryStorage.find(1) #=> <Item @id: 1 @name: 'Item one' @amount: 10>

# retrieving all stored objects
MemoryStorage.all #=> [<Item @id: 1 @name: 'Item one'  @amount: 10>]

Enumerable

MemoryStorage includes Enumerable, so every method defined in Enumerable can be used:

MemoryStorage.save(Item.new(1,'one', 1))
MemoryStorage.save(Item.new(2,'one', 2))
MemoryStorage.save(Item.new(3,'one', 3))

MemoryStorage.inject(0) {|sum, item| sum + item.amount } #=> 6

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

See the LICENSE.

FAQs

Package last updated on 06 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc