javascript 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +4 -4
- data/javascript.gemspec +3 -3
- data/lib/javascript.rb +13 -1
- data/lib/javascript/version.rb +1 -1
- data/test/javascript_test.rb +19 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35a73b23b9db672ea87d3187f92567b94051abca
|
4
|
+
data.tar.gz: d7fe17e2784bba1dfeb2853732de58a880f663cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cd10453b98dde3861a11947ced9713145acd06891c330ec4a8ccade93257328a82ccf43cc091a7f0523fedd65a7880f07d82574ab9016bfbd87b98084a86eaa
|
7
|
+
data.tar.gz: 3c59e0457659f62b27feb126241108a8971ef16076116d2fc40f1a55cf6e60709ef0c6dfb7dc3e44414bb031ea464272a344d6129317cb28135cad65deeaae1c
|
data/.gitignore
CHANGED
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
|
4
|
-
have no choice but to use JavaScript. With this gem, Rubyists can
|
5
|
-
harness the raw power of their machines by programming in JavaScript
|
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
|
13
|
-
"metal by programming in JavaScript syntax right
|
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
|
-
|
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
|
data/lib/javascript/version.rb
CHANGED
data/test/javascript_test.rb
CHANGED
@@ -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.
|
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:
|
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
|
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.
|
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:
|