sometimes 0.0.1 → 0.0.2
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 +44 -11
- data/lib/sometimes/version.rb +1 -1
- data/lib/sometimes.rb +1 -1
- data/test/test_sometimes.rb +12 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# Sometimes
|
2
2
|
|
3
|
-
|
3
|
+
Stop being so black and white. Mix things up a bit and execute code *sometimes*.
|
4
|
+
|
5
|
+
A (very) simple collection of lil' helpers polluting namespaces because...why the hell not?
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
7
|
-
|
9
|
+
Works with only ruby 1.9.2 and up for now because I'm lazy and like the Random class.
|
10
|
+
|
11
|
+
Add this line to your Gemfile:
|
8
12
|
|
9
13
|
gem 'sometimes'
|
10
14
|
|
@@ -12,18 +16,47 @@ And then execute:
|
|
12
16
|
|
13
17
|
$ bundle
|
14
18
|
|
15
|
-
|
19
|
+
Require when needed
|
16
20
|
|
17
|
-
|
21
|
+
require 'sometimes'
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
21
|
-
|
25
|
+
Say something every other time
|
26
|
+
|
27
|
+
sometimes do
|
28
|
+
puts "Hey, you are awesome. You really are." # executes warm fuzzies 50% of the time
|
29
|
+
end
|
30
|
+
|
31
|
+
Maybe you want to do something several times, but not always the exact same number of times
|
32
|
+
|
33
|
+
(4..10).times do
|
34
|
+
pick_nose # between 4 and 10 boogers made, it's unpredictable!
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
Maybe you want to remind someone of something, but not toooo often (It gets annoying!)
|
39
|
+
|
40
|
+
15.percent_of_the_time do
|
41
|
+
puts "Howdy, Don't forget to register!" # be annoying, but only 15% of the time
|
42
|
+
end
|
43
|
+
|
44
|
+
33.percent_of_the time do
|
45
|
+
be_very_polite
|
46
|
+
end
|
47
|
+
|
48
|
+
Share a rare moment with your user
|
49
|
+
|
50
|
+
rarely do
|
51
|
+
puts "How would you like some spammy spam spam!" # be really annoying about 5% of the time
|
52
|
+
end
|
53
|
+
|
54
|
+
1.percent_of_the_time do
|
55
|
+
puts "Want to see something really cool?"
|
56
|
+
end
|
57
|
+
|
58
|
+
## Why?
|
22
59
|
|
23
|
-
|
60
|
+
This gem was made so [alonetone](http://github.com/sudara/alonetone) could bit more fun when displaying notices and communicating to our users.
|
24
61
|
|
25
|
-
|
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
|
62
|
+
We are human, and have personality. Shouldn't our applications reflect this? Be predictable where it counts. But toss in some spice here and there — it is always a good thing.
|
data/lib/sometimes/version.rb
CHANGED
data/lib/sometimes.rb
CHANGED
@@ -20,7 +20,7 @@ require "sometimes/version"
|
|
20
20
|
class Fixnum
|
21
21
|
def percent_of_the_time(&block)
|
22
22
|
raise(ArgumentError, 'Fixnum should be between 1 and 100 to be used with the times method') unless self > 0 && self <= 100
|
23
|
-
yield
|
23
|
+
yield if (Kernel.rand(99)+1) <= self
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
data/test/test_sometimes.rb
CHANGED
@@ -27,7 +27,7 @@ class SometimesTest < Test::Unit::TestCase
|
|
27
27
|
i += 1
|
28
28
|
end
|
29
29
|
end
|
30
|
-
assert i <
|
30
|
+
assert i < 8000
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_99
|
@@ -39,4 +39,15 @@ class SometimesTest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
assert i > 97000
|
41
41
|
end
|
42
|
+
|
43
|
+
def test_1
|
44
|
+
i = 0
|
45
|
+
100000.times do
|
46
|
+
1.percent_of_the_time do
|
47
|
+
i += 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
assert i < 1000
|
51
|
+
end
|
52
|
+
|
42
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sometimes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-
|
12
|
+
date: 2013-01-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Be random. Be unpredictable. But only sometimes
|
15
15
|
email:
|