Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

#ruby is now #send

  • Loading branch information...
commit 92cc238e761e3940034dbf2c697e541e4e023d3b 1 parent b55d649
@txus authored
View
18 Readme.md
@@ -122,23 +122,23 @@ Noscript.
To reopening a Ruby class from Noscript, just prefix the constant with the
namespace `Ruby`, like this: `Ruby.Array`. This is the actual `Array` class. To
-call an arbitrary ruby method on an object, we use the special method `ruby`,
+call an arbitrary ruby method on an object, we use the special method `send`,
which acts like ruby `send`:
- Ruby.Array.ruby('name') # => "Array"
+ Ruby.Array.send('name') # => "Array"
-There are a couple of convenience methods that bypass the `#ruby` convention,
+There are a couple of convenience methods that bypass the `#send` convention,
namely `#def`, `#include` and `#extend`. Let's reopen Array and define a new
method:
Ruby.Array.def('sum', ->
- @ruby('reduce', '+')
+ @send('reduce', '+')
end)
Since Noscript arrays are instances of the ruby Array class, `#sum` should be
-also available to them using the `#ruby` convention:
+also available to them using the `#send` convention:
- [1,2,3].ruby('sum') # => 6
+ [1,2,3].send('sum') # => 6
### Defining new classes and modules
@@ -150,10 +150,10 @@ This is useful if, for example, you want to develop a Rails application but
want to write the model layer entirely in Noscript. Let's do this:
Ruby.Post = Ruby.Class.create(Ruby.ActiveRecord.Base, ->
- @ruby('validates_presence_of', 'title', 'body')
+ @send('validates_presence_of', 'title', 'body')
@def('upcase_title', ->
- @ruby('title').ruby('upcase')
+ @send('title').send('upcase')
end)
end)
@@ -166,7 +166,7 @@ You can also create mixins and include/extend them in your objects:
Ruby.Post.include(mixin)
post = Ruby.Post.new()
- post.ruby('answer') # => 42
+ post.send('answer') # => 42
Last but not least, let's use this Post model from Ruby. Imagine we had this
post saved in `post.ns`. In our Ruby script we have to do this:
View
35 lib/noscript/runtime.rb
@@ -167,7 +167,7 @@ def noscript_send(name, *args)
__noscript_put__(slot)
end
- noscript_def("ruby") do |*args|
+ noscript_def("send") do |*args|
send *args
end
@@ -187,39 +187,6 @@ class Empty
class Runtime
Object = ::Object.new
- # class ObjectKind
- # include Noscriptable
- # noscript_def("clone") do |*args|
- # obj = ObjectKind.new
- # obj.__noscript_prototype__ = self
- # if properties = args.first
- # properties.keys.each do |k|
- # obj.__noscript_put__(k.to_sym, properties[k])
- # end
- # end
- # obj
- # end
-
- # noscript_def("each slot") do |*args|
- # fn = args.shift
- # __noscript_slots__.to_a.each do |k, v|
- # fn.call(self, k.to_s, v)
- # end
- # end
-
- # noscript_def("puts") do |*args|
- # puts(*args)
- # end
-
- # noscript_def("put") do |k, v|
- # __noscript_put__(k, v)
- # end
-
- # noscript_def("get") do |slot|
- # __noscript_get__(slot)
- # end
- # end
- # Object = ObjectKind.new
end
class Function
View
2  test/compiler_test.rb
@@ -199,7 +199,7 @@ def test_self_equals_deref_on_asignment
end
def test_ruby_call
- identifier = compile("Noscript.AST.Identifier.ruby('new', 1, 'foo')")
+ identifier = compile("Noscript.AST.Identifier.send('new', 1, 'foo')")
assert_equal 1, identifier.line
assert_equal 'foo', identifier.name
end
View
2  test/interop_test.rb
@@ -25,7 +25,7 @@ def test_assign_toplevel_namespace
def test_define_ruby_method
compile(<<-CODE)
Ruby.Array.def('sum', ->
- @ruby('reduce', '+')
+ @send('reduce', '+')
end)
CODE
Please sign in to comment.
Something went wrong with that request. Please try again.