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

34 lines
805 B
Ruby
Raw Normal View History

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()
when Method then C::FunctionTemplate.new(&value.to_proc).GetFunction()
2009-12-18 02:48:06 -05:00
else
value
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
2009-12-18 02:48:06 -05:00
end
end
end