observer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d13d39ae847146041e907bf28d80e935ffb9a66fe17732aee6d771a2b498c70
4
- data.tar.gz: d3d8c323e5123580182123608f1edee5d1809b1425b252de6d0565a0b4ebb469
3
+ metadata.gz: e5ed7cfbd45f9cdb1aa8cdb4d034f698d8c32db099779a79938f2ad6113de4c7
4
+ data.tar.gz: 7e4f82ed29989ba629de36307c4d86035dd6a754354b1a28fec3e44fe0144c62
5
5
  SHA512:
6
- metadata.gz: ac108bd869e763925361421caadaf54b42d106ae6542334b82b016d297418ab9567bdf9b6683ef0413409b37b6cee1ca8c31abc963caaa5054b91e33a1140915
7
- data.tar.gz: 897947b7a0cfa4a46ad4354dabc5a20abc18e11a9f5217853fa714db044ca66c87fea8aba31df76bb7d1fab018e98a33aead44659c818375518e29d63e8a0579
6
+ metadata.gz: cd296486efd6f7eb515a206eadd3e5ac243625aa98ad7e189a2a7cdaaef9752656d474eca431054ba21b8973dc0ffd288a142fa531c59759c035695580fe2f00
7
+ data.tar.gz: af2eca1b8d7b67d2fc7fbb69345c7450286b0fa47507a96d18109f2586897f223c52c260408bebbf90211d736e1bf6863f1c4214e6989ea040683732a8cba1eb
@@ -111,7 +111,32 @@
111
111
  # Current price: 112
112
112
  # Current price: 79
113
113
  # --- Sun Jun 09 00:10:25 CDT 2002: Price below 80: 79
114
+ #
115
+ # === Usage with procs
116
+ #
117
+ # The +#notify_observers+ method can also be used with +proc+s by using
118
+ # the +:call+ as +func+ parameter.
119
+ #
120
+ # The following example illustrates the use of a lambda:
121
+ #
122
+ # require 'observer'
123
+ #
124
+ # class Ticker
125
+ # include Observable
126
+ #
127
+ # def run
128
+ # # logic to retrieve the price (here 77.0)
129
+ # changed
130
+ # notify_observers(77.0)
131
+ # end
132
+ # end
133
+ #
134
+ # ticker = Ticker.new
135
+ # warner = ->(price) { puts "New price received: #{price}" }
136
+ # ticker.add_observer(warner, :call)
137
+ # ticker.run
114
138
  module Observable
139
+ VERSION = "0.1.1"
115
140
 
116
141
  #
117
142
  # Add +observer+ as an observer on this object. So that it will receive
@@ -194,7 +219,7 @@ module Observable
194
219
  if defined? @observer_state and @observer_state
195
220
  if defined? @observer_peers
196
221
  @observer_peers.each do |k, v|
197
- k.send v, *arg
222
+ k.__send__(v, *arg)
198
223
  end
199
224
  end
200
225
  @observer_state = false
@@ -1,19 +1,22 @@
1
- begin
2
- require_relative "lib/observer/version"
3
- rescue LoadError # Fallback to load version file in ruby core repository
4
- require_relative "version"
1
+ # frozen_string_literal: true
2
+
3
+ name = File.basename(__FILE__, ".gemspec")
4
+ version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
5
+ break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
6
+ /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
7
+ end rescue nil
5
8
  end
6
9
 
7
10
  Gem::Specification.new do |spec|
8
- spec.name = "observer"
9
- spec.version = Observer::VERSION
11
+ spec.name = name
12
+ spec.version = version
10
13
  spec.authors = ["Yukihiro Matsumoto"]
11
14
  spec.email = ["matz@ruby-lang.org"]
12
15
 
13
16
  spec.summary = %q{Implementation of the Observer object-oriented design pattern.}
14
17
  spec.description = spec.summary
15
18
  spec.homepage = "https://github.com/ruby/observer"
16
- spec.license = "BSD-2-Clause"
19
+ spec.licenses = ["Ruby", "BSD-2-Clause"]
17
20
 
18
21
  spec.metadata["homepage_uri"] = spec.homepage
19
22
  spec.metadata["source_code_uri"] = spec.homepage
@@ -21,7 +24,7 @@ Gem::Specification.new do |spec|
21
24
  # Specify which files should be added to the gem when it is released.
22
25
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
26
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ `git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
28
  end
26
29
  spec.bindir = "exe"
27
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: observer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-08 00:00:00.000000000 Z
11
+ date: 2020-12-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Implementation of the Observer object-oriented design pattern.
14
14
  email:
@@ -26,15 +26,15 @@ files:
26
26
  - bin/console
27
27
  - bin/setup
28
28
  - lib/observer.rb
29
- - lib/observer/version.rb
30
29
  - observer.gemspec
31
30
  homepage: https://github.com/ruby/observer
32
31
  licenses:
32
+ - Ruby
33
33
  - BSD-2-Clause
34
34
  metadata:
35
35
  homepage_uri: https://github.com/ruby/observer
36
36
  source_code_uri: https://github.com/ruby/observer
37
- post_install_message:
37
+ post_install_message:
38
38
  rdoc_options: []
39
39
  require_paths:
40
40
  - lib
@@ -49,8 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
- rubygems_version: 3.2.0.pre1
53
- signing_key:
52
+ rubygems_version: 3.2.2
53
+ signing_key:
54
54
  specification_version: 4
55
55
  summary: Implementation of the Observer object-oriented design pattern.
56
56
  test_files: []
@@ -1,3 +0,0 @@
1
- module Observer
2
- VERSION = "0.1.0"
3
- end