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

list

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

list

  • 0.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

List

List in Ruby.

Build Status

List is a class of wrapped singly-linked list.

It's can use same as Array. But processing speed is different.

Usage

All interface is same with Array class.

> Array.methods - List.methods
=> []
> Array.new.methods - List.new.methods
=> []

List can use instead of Array.

require 'list'

list = List.new # or List[]
list.push 1,2,3
list.pop #=> 3
list[0,2] #=> List[1,2]
list[0,1] = 5
list.each do |i|
  puts i #=> 5,2
end
puts List[1,2,3].map{|i| i * i}.inject(:+) #=> 14
+---------+  +->+---------+  +->+---------+
|  value  |  |  |  value  |  |  |  value  |
|  next   |--+  |  next   |--+  |  next   |
+---------+     +---------+     +---------+

But, List is not Array.

list = List[1,2,3]
list.ring.each do |i|
  puts i # print infinitely 1,2,3,1,2,3,1,2...
end
+->+---------+  +->+---------+  +->+---------+
|  |  value  |  |  |  value  |  |  |  value  |
|  |  next   |--+  |  next   |--+  |  next   |--+
|  +---------+     +---------+     +---------+  |
+-----------------------------------------------+

Feature

  • List have all same method and behavior with Array.
  • include Enumeratable
  • insert and delete is more faster than Array.
  • Can use MRI at version 1.9.3, 2.0.0 and 2.1.0.

Other API

List#ring: experimental method for expressing the ring buffer.

List#ring!: change self to ring buffer.

List#ring?: check self to ring buffer.

Enumeratable#to_list: all class of included Enumeratable, can convert to List instance

List#to_list: return self.

List#to_a: change from List to Array.

Installation

Add this line to your application's Gemfile:

gem 'list'

And then execute:

$ bundle

Or install it yourself as:

$ gem install list

Testing

This library is tested using Travis.

  • MRI 2.0.0
  • MRI 2.1.6
  • MRI 2.2.2

Contributing

  1. Fork it ( http://github.com/ksss/list/fork )
  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

Other

RDoc for Array

benchmark script result

wikipedia

FAQs

Package last updated on 07 Jun 2015

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