randomfromrange 0.0.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.
Files changed (2) hide show
  1. data/lib/randomfromrange.rb +13 -0
  2. metadata +46 -0
@@ -0,0 +1,13 @@
1
+ # Ruby 1.9.3 Range for Kernel.random update backwards compatibility
2
+ Kernel.class_eval do
3
+ alias :old_rand :rand
4
+ def rand(v=nil)
5
+ if(v.respond_to? :to_i)
6
+ return old_rand(v.to_i.abs)
7
+ elsif(v.respond_to? :begin and v.respond_to? :end)
8
+ return ((v.end-v.begin)*old_rand() + v.begin)
9
+ else
10
+ raise TypeError, 'can\'t convert ' + v.class + ' into Integer'
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: randomfromrange
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Julian Rupp
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Provides older Ruby versions with Ruby 1.9.3''s change to Kernel.rand:
15
+ the ability to pass a Range object as argument.'
16
+ email: mail@julian-rupp.eu
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/randomfromrange.rb
22
+ homepage: http://rubygems.org/gems/randomfromrange
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.25
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Modifies Kernel.rand to also accept Ranges
46
+ test_files: []