only_once 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/only_once.rb +12 -0
  2. metadata +66 -0
data/lib/only_once.rb ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Do something, but only once (in the lifetime of the program). This is based on
4
+ # the output of caller() and the value of _args_, so there's some possibility
5
+ # for error if you've reloaded files, etc.
6
+ def only_once(*args)
7
+ $only_once_previously_called_from ||= Array.new
8
+ unless $only_once_previously_called_from.include? [caller[0], args]
9
+ $only_once_previously_called_from << [caller[0], args]
10
+ yield
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: only_once
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - katmagic
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-20 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Run a block only once during the lifetime of a program.
22
+ email: the.magical.kat@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/only_once.rb
31
+ has_rdoc: true
32
+ homepage: https://github.com/katmagic/only_once
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirements: []
59
+
60
+ rubyforge_project: only_once
61
+ rubygems_version: 1.3.7
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Execute something, but only once.
65
+ test_files: []
66
+