lxa_core_extensions 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,29 +1,38 @@
1
1
  # LxaCoreExtensions
2
2
 
3
- TODO: Write a gem description
4
3
 
5
- ## Installation
4
+ [![Build Status](https://travis-ci.org/levinalex/lxa_core_extensions.png)](https://travis-ci.org/levinalex/lxa_core_extensions)
5
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/levinalex/lxa_core_extensions)
6
6
 
7
- Add this line to your application's Gemfile:
7
+ simple core extensions for ruby:
8
8
 
9
- gem 'lxa_core_extensions'
9
+ ### Constants
10
+
11
+ Infinity #=> Infinity
12
+ NaN #=> NaN
13
+
14
+ ### Enumerable#build_hash
15
+
16
+ [[1,2],[3,4],[5,6]].build_hash #=> {1=>2, 3=>4, 5=>6}
17
+ [[1,2],[3,4],[5,6]].build_hash(:last) #=> {2=>[1,2], 4=>[3,4], 6=>[5,6]}
10
18
 
11
- And then execute:
19
+ ### Hash#compact
12
20
 
13
- $ bundle
21
+ { 4=>35, 9=>nil, 10=>false }.compact #=> {4=>35, 10=>false}
14
22
 
15
- Or install it yourself as:
23
+ ### Hash#rekey
16
24
 
17
- $ gem install lxa_core_extensions
25
+ {1=>2, 3=>4, 5=>{6=>7, 8=>9}}.rekey(&:to_s) #=> {"1"=>2,"3"=>4, "5"=>{"6"=>7, "8"=>9}}
18
26
 
19
- ## Usage
27
+ ### Hash#nested_keys
20
28
 
21
- TODO: Write usage instructions here
29
+ {1=>{2=>3,4=>5}}.nested_keys.to_a #=> [1,2,4]
22
30
 
23
- ## Contributing
31
+ ### Hash#flip
32
+
33
+ {1=>2, 3=>4, 5=>6, 6=>2, 7=>4}.flip #=> {2=>[1, 6], 4=>[3, 7], 6=>[5]}
34
+
35
+ ## Installation
36
+
37
+ gem 'lxa_core_extensions'
24
38
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
@@ -3,4 +3,9 @@ class Array
3
3
  raise "called Array#only with array of length #{length}" if length != 1
4
4
  first
5
5
  end
6
+
7
+ def random_element
8
+ idx = rand(self.length)
9
+ self[idx]
10
+ end
6
11
  end
@@ -1,3 +1,3 @@
1
1
  module LxaCoreExtensions
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_development_dependency "minitest"
21
+ gem.add_development_dependency "rake"
21
22
  end
data/test/test_array.rb CHANGED
@@ -15,4 +15,9 @@ describe "Array#only" do
15
15
  assert_equal(12, [12].only)
16
16
  end
17
17
 
18
+ it "should return a random element" do
19
+ arr = [:a,:b,:c,:d]
20
+ assert_includes arr, arr.random_element
21
+ end
22
+
18
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lxa_core_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-30 00:00:00.000000000 Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: simple core extensions
31
47
  email:
32
48
  - mail@levinalex.net
@@ -64,12 +80,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
80
  - - ! '>='
65
81
  - !ruby/object:Gem::Version
66
82
  version: '0'
83
+ segments:
84
+ - 0
85
+ hash: -2106405039464562958
67
86
  required_rubygems_version: !ruby/object:Gem::Requirement
68
87
  none: false
69
88
  requirements:
70
89
  - - ! '>='
71
90
  - !ruby/object:Gem::Version
72
91
  version: '0'
92
+ segments:
93
+ - 0
94
+ hash: -2106405039464562958
73
95
  requirements: []
74
96
  rubyforge_project:
75
97
  rubygems_version: 1.8.24
@@ -82,4 +104,3 @@ test_files:
82
104
  - test/test_constants.rb
83
105
  - test/test_enumerable.rb
84
106
  - test/test_hash.rb
85
- has_rdoc: