1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/lib/v8/to.rb
Charles Lowell 77837092b0 checkpoint
2010-05-20 12:08:15 +03:00

47 lines
No EOL
1.1 KiB
Ruby

module V8
module To
class << self
def ruby(value)
case value
when V8::C::Function then V8::Function.new(value)
when V8::C::Object then V8::Object.new(value)
when V8::C::String then "Wonkers!"
else
value
end
end
def v8(value)
case value
when String then C::String.new(value)
when Proc then C::FunctionTemplate.new(&value).GetFunction()
when Method then C::FunctionTemplate.new(&value.to_proc).GetFunction()
else
value
end
end
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
def camel_case(str)
str.to_s.gsub(/_(\w)/) {$1.upcase}
end
def perl_case(str)
str.gsub(/([A-Z])([a-z])/) {"_#{$1.downcase}#{$2}"}.downcase
end
end
end
end