return_many 0.0.42.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZGRlOGQxNjNhYTY4N2RlNmY0NGY1NDk4MjVkYzZlN2MwY2IxNjJlMA==
5
+ data.tar.gz: !binary |-
6
+ YTkxMDRmYzBlYTg1MzQ2YWQ2MDdkNmM4YjZiOWIzNWFmZDU4NjRmYQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ODQyYjBlYzk2M2NmOWZkMTIyNGE5MTQ2MGQ0ZTY4YzhlZjgyMTQzNGY1YjZj
10
+ N2E5ZWU4MWFkNjViYjZjMmRhOWJlNWExZGM1ZjgxZTc4YmFlNDdkZGIzNDIx
11
+ NTk5ZmYxOTNhYTljNzQzNDZjZTNmZTI5NmU2NzBiNjgwMWMzN2Y=
12
+ data.tar.gz: !binary |-
13
+ ZTg1YzBiYWU2MzhjZTI5YTkwNDIzMmU3NDYwZDVjZGM1NjgzMWIxZDA3ODhl
14
+ MTUwYjUwNjQ2MDJhYTQ1MzJiZTkyOTM1OTRkZmYwYmNmMjczY2ZjNDM3M2I3
15
+ NjVmYzFiMjQ5MTRiNTkwNTlkZWJmMTcxZTA0MTM5NTZiZWRmZmY=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in return_many.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Darek Nedza
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # ReturnMany - Tested with 1.9.3, may not work with 2+ (because of keyword arguments)
2
+
3
+ Little method that makes returning many values easier and better.
4
+ You can access returned values via hash-like function `[:name]`.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'return_many'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install return_many
19
+
20
+ ## Usage
21
+
22
+ You have to require gem:
23
+
24
+ require 'return_many'
25
+
26
+ And you can include (module) whenever you want.
27
+ If you require it outside any module/class it will be avaible globally.
28
+
29
+ include ReturnMany
30
+
31
+ Now you can use it via `many` function:
32
+
33
+ def qux
34
+ return many a: 1, b: 2, c: 3 # and so on
35
+ end
36
+
37
+ # lets create little function, so I don‘t have to make a lot of function-examples
38
+ # it takes and returns arguments:
39
+ def foo args
40
+ return many args
41
+ end
42
+
43
+ a, b = foo a: 1, b: 2
44
+ # a = 1; b = 2
45
+
46
+ `c` will have the 3rd+ args
47
+ a, b, *c = foo a: 1, b: 2, c: 3, d: 4
48
+ # a = 1; b = 2; c = [3, 4]
49
+
50
+ Takes only a and c
51
+
52
+ a, c = foo( a: 1, b: 2, c: 3 )[:a, :c]
53
+ # a = 1; c = 3
54
+
55
+ Takes selected return values as array:
56
+
57
+ a = foo( a: 1, b: 2, c: 3)[:a, :c]
58
+ # a = [1, 3]
59
+
60
+ Returns modyfied hash:
61
+
62
+ a = foo( a: 1, b: 2)
63
+ # a= {:a=>1, :b=>2}
64
+
65
+ So you can do the same thing as above:
66
+ a[:a, :b, :b]
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
@@ -0,0 +1,36 @@
1
+ require "return_many/version"
2
+
3
+ module ReturnMany
4
+ MultipleReturn = Class.new(Hash) do
5
+ attr_reader :arg
6
+
7
+ # copy-paste hash into my class
8
+ def initialize arg
9
+ # self.merge arg
10
+ super
11
+ for k,v in arg
12
+ self[k]=v
13
+ end
14
+
15
+ end
16
+
17
+ # called when you use splat operator
18
+ # (e.g. a, *b = [1,2]; * - splat operator)
19
+ def to_ary
20
+ self.values
21
+ end
22
+
23
+ # getting few keys instead of 1
24
+ # for example: h[:a, :b]
25
+ def [] *args
26
+ args.each.collect do |arg|
27
+ super(arg)
28
+ end
29
+ end
30
+ end
31
+
32
+ def many args
33
+ MultipleReturn.new args
34
+ end
35
+
36
+ end
@@ -0,0 +1,3 @@
1
+ module ReturnMany
2
+ VERSION = "0.0.42.pre"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'return_many/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "return_many"
8
+ spec.version = ReturnMany::VERSION
9
+ spec.authors = ["Darek Nedza"]
10
+ spec.email = ["nedzadarek@gmail.com"]
11
+ spec.description = %q{Returns many values from the method. You can extract it via order or via names.}
12
+ spec.summary = %q{Returns many values and extract it via hash-like functions.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,37 @@
1
+ require 'return_many'
2
+ require 'test/unit'
3
+ include ReturnMany
4
+
5
+ class TestMultipleReturn < Test::Unit::TestCase
6
+ def test_return_one
7
+ # bad
8
+ random_number = rand(42)
9
+ # results = MultipleReturn.new(expected)
10
+ # assert_equal(expected, results)
11
+ result = MultipleReturn.new a: random_number
12
+ assert_equal({a: random_number}, result)
13
+ end
14
+
15
+ def test_return_multiple
16
+ exp1, exp2, exp3 = rand(42), rand(42), rand(42)
17
+
18
+ res1, res2, res3 = MultipleReturn.new a: exp1, b: exp2, c: exp3
19
+
20
+
21
+ assert_equal(exp1, res1)
22
+ assert_equal(exp2, res2)
23
+ assert_equal(exp3, res3)
24
+
25
+ end
26
+
27
+ def test_return_2_from_3
28
+ exp1, exp2, exp3 = rand(42), rand(42), rand(42)
29
+
30
+ res1, res3 = MultipleReturn.new(a: exp1, b: exp2, c: exp3)[:a,:c]
31
+
32
+ assert_equal(exp1, res1)
33
+ # assert_equal(exp2, res2)
34
+ assert_equal(exp3, res3)
35
+ end
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: return_many
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.42.pre
5
+ platform: ruby
6
+ authors:
7
+ - Darek Nedza
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Returns many values from the method. You can extract it via order or
42
+ via names.
43
+ email:
44
+ - nedzadarek@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/return_many.rb
55
+ - lib/return_many/version.rb
56
+ - return_many.gemspec
57
+ - test/test_return_many.rb
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>'
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.1
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.6
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Returns many values and extract it via hash-like functions.
82
+ test_files:
83
+ - test/test_return_many.rb
84
+ has_rdoc: