2009-12-18 02:48:06 -05:00
|
|
|
|
|
|
|
module V8
|
|
|
|
module To
|
|
|
|
class << self
|
|
|
|
def ruby(value)
|
|
|
|
case value
|
2010-04-21 19:09:13 -04:00
|
|
|
when V8::C::Function then V8::Function.new(value)
|
|
|
|
when V8::C::Object then V8::Object.new(value)
|
|
|
|
when V8::C::String then "Wonkers!"
|
2009-12-18 02:48:06 -05:00
|
|
|
else
|
|
|
|
value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def v8(value)
|
|
|
|
case value
|
|
|
|
when String then C::String.new(value)
|
|
|
|
when Proc then C::FunctionTemplate.new(&value).GetFunction()
|
2009-12-20 12:31:02 -05:00
|
|
|
when Method then C::FunctionTemplate.new(&value.to_proc).GetFunction()
|
2009-12-18 02:48:06 -05:00
|
|
|
else
|
|
|
|
value
|
|
|
|
end
|
|
|
|
end
|
2010-05-12 18:30:53 -04:00
|
|
|
|
|
|
|
def rb(value)
|
|
|
|
puts "hello from To.rb"
|
|
|
|
if value.IsFunction()
|
|
|
|
V8::Function.new(value)
|
|
|
|
elsif value.IsObject()
|
|
|
|
V8::Object.new(value)
|
|
|
|
elsif value.IsNumber()
|
|
|
|
value.NumberValue()
|
|
|
|
elsif value.IsBoolean()
|
|
|
|
value.BooleanValue()
|
|
|
|
end
|
|
|
|
end
|
2010-01-10 04:37:51 -05:00
|
|
|
|
2010-01-17 18:12:23 -05:00
|
|
|
def camel_case(str)
|
2010-01-10 04:37:51 -05:00
|
|
|
str.to_s.gsub(/_(\w)/) {$1.upcase}
|
2010-01-17 17:25:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def perl_case(str)
|
|
|
|
str.gsub(/([A-Z])([a-z])/) {"_#{$1.downcase}#{$2}"}.downcase
|
|
|
|
end
|
2009-12-18 02:48:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|