javascript 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 0af8711d86c041ab8cad64c4e6ba00018a4a8c64
4
- data.tar.gz: a09bb05335d5b5abb69d49704da1be8a8c07877c
3
+ metadata.gz: 35a73b23b9db672ea87d3187f92567b94051abca
4
+ data.tar.gz: d7fe17e2784bba1dfeb2853732de58a880f663cf
5
5
  SHA512:
6
- metadata.gz: 6244a60dfbd08cb24a99c38fd5d487de584451e958c385a69239dbb8b091f3ce508a0bc378297b3f3098c6a51e461bbb4a887df69ab5329f3e55e653f2a58a64
7
- data.tar.gz: f51ac7b1c6a9462807110531081e3fa8b904cdb60b61c5bea1c287d6531957f3f85b366fcfdcf67bc7b6a34e527866b07f6878cde4e4330f940c279587a5dac9
6
+ metadata.gz: 4cd10453b98dde3861a11947ced9713145acd06891c330ec4a8ccade93257328a82ccf43cc091a7f0523fedd65a7880f07d82574ab9016bfbd87b98084a86eaa
7
+ data.tar.gz: 3c59e0457659f62b27feb126241108a8971ef16076116d2fc40f1a55cf6e60709ef0c6dfb7dc3e44414bb031ea464272a344d6129317cb28135cad65deeaae1c
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # JavaScript
2
2
 
3
- As much as we love writing Ruby, when you need to *get closer to the metal*, you
4
- have no choice but to use JavaScript. With this gem, Rubyists can finally
5
- harness the raw power of their machines by programming in JavaScript syntax
6
- *right inside their Ruby applications*.
3
+ As much as we love writing Ruby, when you need to *get really close to the
4
+ metal*, you have no choice but to use JavaScript. With this gem, Rubyists can
5
+ finally harness the raw power of their machines by programming in JavaScript
6
+ syntax *right inside their Ruby applications*.
7
7
 
8
8
  ## Installation
9
9
 
data/javascript.gemspec CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Godfrey Chan"]
10
10
  spec.email = ["godfreykfc@gmail.com"]
11
11
  spec.summary = "Harness the raw power of your machine with JavaScript"
12
- spec.description = "With this gem, Rubyists can finally get closer to the " \
13
- "metal by programming in JavaScript syntax right within " \
14
- "their Ruby applications."
12
+ spec.description = "With this gem, Rubyists can finally get really close " \
13
+ "to the metal by programming in JavaScript syntax right " \
14
+ "within their Ruby applications."
15
15
  spec.homepage = "https://github.com/vanruby/javascript"
16
16
  spec.license = "MIT"
17
17
 
data/lib/javascript.rb CHANGED
@@ -180,9 +180,21 @@ module JavaScript
180
180
 
181
181
  def __eval__(*args, &block)
182
182
  JavaScript.current_scope = self
183
- __method__(:instance_exec).call(*args, &block)
183
+
184
+ # convert the block to a lambda, so that +return+ works correctly
185
+ temp = :"block_#{Time.now.to_i}"
186
+ metaclass = __method__(:singleton_class).call
187
+
188
+ metaclass.send(:define_method, temp, &block)
189
+
190
+ if block.arity.zero?
191
+ __method__(:send).call(temp)
192
+ else
193
+ __method__(:send).call(temp, *args)
194
+ end
184
195
  ensure
185
196
  JavaScript.current_scope = @parent
197
+ metaclass.send(:remove_method, temp)
186
198
  end
187
199
 
188
200
  private
@@ -1,3 +1,3 @@
1
1
  module JavaScript
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -101,6 +101,25 @@ class JavaScriptTest < TestCase
101
101
  assert_messages "a: hello", "b: hello", "a: c", "b: c"
102
102
  end
103
103
 
104
+ test "Functions can return a value" do
105
+ require "javascript"
106
+
107
+ javascript {
108
+ function identity(x) {
109
+ return x;
110
+ }
111
+
112
+ function square(x) {
113
+ return x * x;
114
+ }
115
+
116
+ console.log(identity("Hello world!"));
117
+ console.log(square(2));
118
+ }
119
+
120
+ assert_messages "Hello world!", 4
121
+ end
122
+
104
123
  test "arguments" do
105
124
  require "javascript"
106
125
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: javascript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Godfrey Chan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-07 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -80,8 +80,8 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 4.1.0
83
- description: With this gem, Rubyists can finally get closer to the metal by programming
84
- in JavaScript syntax right within their Ruby applications.
83
+ description: With this gem, Rubyists can finally get really close to the metal by
84
+ programming in JavaScript syntax right within their Ruby applications.
85
85
  email:
86
86
  - godfreykfc@gmail.com
87
87
  executables: []
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.2.2
124
+ rubygems_version: 2.4.6
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Harness the raw power of your machine with JavaScript
@@ -129,3 +129,4 @@ test_files:
129
129
  - test/javascript_test.rb
130
130
  - test/no_conflict_test.rb
131
131
  - test/test_helper.rb
132
+ has_rdoc: