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

linked-list

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linked-list

  • 0.0.16
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Code Climate Build Status Gem Version Coverage Status

LinkedList

Ruby implementation of Doubly Linked List, following some Ruby idioms.

Installation

Add this line to your application's Gemfile:

gem 'linked-list'

And then execute:

$ bundle

Or install it yourself as:

$ gem install linked-list

Usage

object = Object.new # could be anything
list = LinkedList::List.new

list.push(object)
list << object # same as `push`

list.unshift(object)

list.pop
list.shift

list.insert(object, before: object)
list.insert(object, before: ->(n) { n == 'foo' })

list.insert(object, after: object)
list.insert(object, after: ->(n) { n == 'foo' })

list.insert_before(object, node)
list.insert_after(object, node)

list.reverse
list.reverse!

list.delete(object)
list.delete { |n| n == 'foo' }

list.delete_all(object)
list.delete_all { |n| n == 'foo' }

list.each  # Enumerator object
list.each { |e| puts e }

list.reverse_each # Enumerator object
list.reverse_each { |e| puts e }

list.reverse_each_node # Enumerator object
list.reverse_each_node { |node| puts node.data }

list.first # head of the list
list.last # tail of the list

list.length
list.size # same as `length`

list.to_a

Another way to instantiate List or Node is to use conversion functions. First, include LinkedList::Conversions module to your class

class Foo
  include LinkedList::Conversions
end

Now anywhere in your class you can use the following methods

Node(object)           # will return new `Node` object
List(object)           # will return new `List` object with one `Node` object
List([object, object]) # will return new `List` object with two `Node` objects

Please see LinkedList::List, LinkedList::Node, and LinkedList::Conversions for details.

Tests

Run test with

$ rake

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

FAQs

Package last updated on 22 Sep 2021

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