Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose classes, modules and methods to js
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'native' | ||
|
||
describe 'Native exposure' do | ||
describe Class do | ||
describe '#native_alias' do | ||
it 'exposes a method to javascript' do | ||
c = Class.new do | ||
def ruby_method | ||
:ruby | ||
end | ||
|
||
native_alias :rubyMethod, :ruby_method | ||
end | ||
|
||
`#{c.new}.rubyMethod()`.should == :ruby | ||
end | ||
end | ||
|
||
describe '#native_class' do | ||
it 'exposes a Class on the JS global object' do | ||
c = Class.new do | ||
def self.name | ||
'Pippo' | ||
end | ||
|
||
native_class | ||
end | ||
|
||
`Pippo`.should == c | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Module | ||
def native_module | ||
`Opal.global[#{self.name}] = #{self}` | ||
end | ||
end | ||
|
||
class Class | ||
def native_alias(jsid, mid) | ||
`#{self}._proto[#{jsid}] = #{self}._proto['$' + #{mid}]` | ||
end | ||
|
||
alias native_class native_module | ||
end |
c682171
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to delete the old file.
c682171
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh, sorry, thanks for the fix :)