Module: Rhino::To
Overview
:nodoc
Class Method Summary collapse
-
.javascript(object, scope = nil) ⇒ Object
#deprecated use #to_javascript instead.
-
.ruby(object) ⇒ Object
#deprecated use #to_ruby instead.
Instance Method Summary collapse
- #args_to_javascript(args, scope = nil) ⇒ Object
- #args_to_ruby(args) ⇒ Object
- #to_javascript(object, scope = nil) ⇒ Object
- #to_ruby(object) ⇒ Object
Class Method Details
.javascript(object, scope = nil) ⇒ Object
#deprecated use Rhino#to_javascript instead
35 36 37 38 |
# File 'lib/rhino/deprecations.rb', line 35 def self.javascript(object, scope = nil) warn "[DEPRECATION] `Rhino::To.javascript` is deprecated, use `Rhino.to_javascript` instead." to_javascript(object, scope) end |
.ruby(object) ⇒ Object
#deprecated use Rhino#to_ruby instead
29 30 31 32 |
# File 'lib/rhino/deprecations.rb', line 29 def self.ruby(object) warn "[DEPRECATION] `Rhino::To.ruby` is deprecated, use `Rhino.to_ruby` instead." to_ruby(object) end |
Instance Method Details
#args_to_javascript(args, scope = nil) ⇒ Object
37 38 39 |
# File 'lib/rhino/wormhole.rb', line 37 def args_to_javascript(args, scope = nil) args.map { |arg| to_javascript(arg, scope) }.to_java end |
#args_to_ruby(args) ⇒ Object
33 34 35 |
# File 'lib/rhino/wormhole.rb', line 33 def args_to_ruby(args) args.map { |arg| to_ruby(arg) } end |
#to_javascript(object, scope = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rhino/wormhole.rb', line 17 def to_javascript(object, scope = nil) case object when NilClass then object when String, Numeric then object when TrueClass, FalseClass then object when JS::Scriptable then object when Array then array_to_javascript(object, scope) when Hash then hash_to_javascript(object, scope) when Time then time_to_javascript(object, scope) when Method, UnboundMethod then Ruby::Function.wrap(object, scope) when Proc then Ruby::Function.wrap(object, scope) when Class then Ruby::Constructor.wrap(object, scope) else RubyObject.wrap(object, scope) end end |
#to_ruby(object) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rhino/wormhole.rb', line 5 def to_ruby(object) case object when JS::Scriptable::NOT_FOUND, JS::Undefined then nil when JS::Wrapper then object.unwrap when JS::NativeArray then array_to_ruby(object) when JS::NativeDate then Time.at(object.getJSTimeValue / 1000) # Rhino 1.7R4 added ConsString for optimized String + operations : when Java::JavaLang::CharSequence then object.toString else object end end |