ruby-tables 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,6 +33,14 @@ in when you create a key well out of bounds. This is not unlike typical ruby Arr
33
33
  ary[ 10 ] = 2
34
34
  ary #=> [ 1, nil, nil, nil, nil, nil, nil, nil, nil, nil, 2 ]
35
35
 
36
+ = Usage
37
+ Install it:
38
+ gem install ruby-tables
39
+
40
+ Use it:
41
+ require "rubygems"
42
+ require "table"
43
+
36
44
  = Examples
37
45
  # as hashes with convient dot notation for keys
38
46
  t1 = Table[ :something => 50, :else => 100 ]
@@ -41,6 +49,11 @@ in when you create a key well out of bounds. This is not unlike typical ruby Arr
41
49
  t1.something #=> 100
42
50
  t1.some_new_key = "sdsdsd"
43
51
  t1.some_new_key #=> "sdsdsd"
52
+ t1.users = Table[ *%w{ Tom Dick Harry }.map { | n | Table[ :name => n ] } ]
53
+
54
+ t1.users.first.name #=> Tom
55
+ t1.users.first.name = "Alex"
56
+ t1.users.map { | u | u.name }.join( ", " ) #=> Alex, Dick, Harry
44
57
 
45
58
  # as a combination of an array and a hash
46
59
  t2 = Table[ 1, 2, 3, 4, 5, { :a => 1000, :b => 2000 }, 6, 7, { :c => 50, :d => 60 }, 8, 9 ]
@@ -53,6 +66,8 @@ in when you create a key well out of bounds. This is not unlike typical ruby Arr
53
66
 
54
67
  # tables can be concatenated
55
68
  t3 = t1 + t2
69
+
70
+ # you can access the array elements or the hash elements as their underlying structures
56
71
  t3.pairs #=> { :something => 50, :else => 100, :a => 1000, :b => 2000, :c => 50, :d => 60 }
57
72
  t3.to_a #=> [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
58
73
  t3.inject { |sum, i | sum + i } #=> 45
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ begin
9
9
  gem.version = version
10
10
  gem.name = "ruby-tables"
11
11
  gem.summary = %Q{Lua tables for Ruby}
12
- gem.description = %Q{A table data structure implemented in Ruby}
12
+ gem.description = %Q{The table data structure from lua implemented in Ruby}
13
13
  gem.email = "nick.loves.rails@gmail.com"
14
14
  gem.homepage = "http://github.com/Abica/ruby-tables"
15
15
  gem.authors = [ "Nicholas Wright" ]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -255,7 +255,7 @@ class Table
255
255
  str = []
256
256
 
257
257
  str << map { | item | item.inspect } if any?
258
- str << "{#{ hsh.map { | key, val | "#{ key.inspect }=>#{ val.inspect }" } }}" if hsh.any?
258
+ str << "{#{ hsh.map { | key, val | "#{ key.inspect }=>#{ val.inspect }" }.join( ", " ) }}" if hsh.any?
259
259
 
260
260
  "Table[#{ str.join( ", " ) }]"
261
261
  end
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-tables}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nicholas Wright"]
12
12
  s.date = %q{2010-02-14}
13
- s.description = %q{A table data structure implemented in Ruby}
13
+ s.description = %q{The table data structure from lua implemented in Ruby}
14
14
  s.email = %q{nick.loves.rails@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "README.rdoc"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Wright
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.2.2
24
24
  version:
25
- description: A table data structure implemented in Ruby
25
+ description: The table data structure from lua implemented in Ruby
26
26
  email: nick.loves.rails@gmail.com
27
27
  executables: []
28
28