ruby.py 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -2
  3. data/lib/ruby.py.rb +8 -6
  4. data/ruby.py.gemspec +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f2b167135a5914b95038929c7098de36bc226cf363a62e0508557ff1566c114
4
- data.tar.gz: 25a87baa586f4a55637467d7a9e7de7e7474bf88eddd854e425715caf84f80b8
3
+ metadata.gz: 76ccc75fe7cc12b89aa59f57750daf86eb92f3bca794351b906d8b28f7d10fb6
4
+ data.tar.gz: 6deeac2d7068e02c931a448cf417c909a3e84a5d0ca6df6f72c146e29c5db691
5
5
  SHA512:
6
- metadata.gz: adf99697fa66ffd22aee9189045d6f1f72a96a90a0128bf7150cab3cecdd28f059ebaba404adb7bda05f06fec37dcdb35958c5eb5ec694aa68105d36d59c77e9
7
- data.tar.gz: c70d594a5b93114c827b1631b2535a7bd9556c971baa7c3883027338716a9cd6e9fd1bdde3bcf8e58f15bc1320b2792e36e6595efe2da8932f9d8cfadd73794f
6
+ metadata.gz: c9ad6a2b349ecf451ffb7f06cbc618b307052a19e34f813e279df107667c0968038e18e019e38cb9759808fbdbe5fd14786b6555540661a2a47b707bf5d27ab0
7
+ data.tar.gz: 471eb06ccf092e52ad0cecd6199679c43290b79702c5377efe33b74f350b7d23ccd8b299cead8706c9eb4ad59f46f80b01af507e4f358adc6bbed712b9e13291
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Ruby.py
2
2
 
3
- Ruby wrapper for Python modules using the (PyCall
4
- gem)[https://rubygems.org/gems/pycall].
3
+ Ruby wrapper for Python modules using the
4
+ (PyCall gem)[https://rubygems.org/gems/pycall].
5
5
 
6
6
  ## Installation
7
7
 
@@ -21,6 +21,8 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
+ ### Consume a Python API in Ruby
25
+
24
26
  ```ruby
25
27
  require 'ruby.py'
26
28
 
@@ -60,6 +62,24 @@ mul = tf.multiply(a, b)
60
62
  result = sess.run(add, feed_dict: { a => 2, b => 3 })
61
63
  ```
62
64
 
65
+ ### Enhance a Python API in Ruby
66
+
67
+ ```ruby
68
+ require 'ruby.py'
69
+
70
+ # Top-level module to expose Python 'tensorflow' API to Ruby.
71
+ TensorFlow = RubyPy.import('tensorflow')
72
+
73
+ # Enhance the module's Ruby API.
74
+ module TensorFlow
75
+ # Pass a tf.Session() to a block and auto-close it.
76
+ def self.session(*args, &block)
77
+ return(s = self.Session.new(*args)) unless block
78
+ begin; yield(s); ensure; s.close; end
79
+ end
80
+ end
81
+ ```
82
+
63
83
  ## Support
64
84
 
65
85
  Open an issue via [GitLab](https://gitlab.com/fjc/ruby.py) or email
@@ -26,21 +26,23 @@ module RubyPy
26
26
  instance_eval("#{<<-"DEFMOD"}\n#{<<-"ENDMOD"}", __FILE__, __LINE__)
27
27
  DEFMOD
28
28
  module #{mod.join('::')}
29
- unless @pycall
30
- @pycall = Module.new do
31
- extend ::PyCall::Import
32
- pyimport #{pym.inspect}, as: 'import'
29
+ unless @_pycall
30
+ def self._pycall
31
+ @_pycall ||= Module.new do
32
+ extend ::PyCall::Import
33
+ pyimport #{pym.inspect}, as: 'import'
34
+ end
33
35
  end
34
36
 
35
37
  def self.method_missing(method_name, *arguments, &block)
36
38
  if respond_to_missing?(method_name)
37
- @pycall.import.send(method_name, *arguments, &block)
39
+ _pycall.import.send(method_name, *arguments, &block)
38
40
  else
39
41
  super
40
42
  end
41
43
  end
42
44
  def self.respond_to_missing?(method_name, include_private = false)
43
- @pycall.import.respond_to?(method_name, include_private)
45
+ _pycall.import.respond_to?(method_name, include_private)
44
46
  end
45
47
  end
46
48
 
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'ruby.py'
6
- spec.version = '0.2.5'
6
+ spec.version = '0.2.6'
7
7
  spec.authors = ['Frank J. Cameron']
8
8
  spec.email = ['fjc@fastmail.net']
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby.py
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank J. Cameron
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-11 00:00:00.000000000 Z
11
+ date: 2018-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler