Module: V8::To

Defined in:
lib/v8/to.rb

Class Method Summary collapse

Class Method Details

.camel_case(str) ⇒ Object


24
25
26
# File 'lib/v8/to.rb', line 24

def camel_case(str)
  str.to_s.gsub(/_(\w)/) {$1.upcase}
end

.perl_case(str) ⇒ Object


28
29
30
# File 'lib/v8/to.rb', line 28

def perl_case(str)
  str.gsub(/([A-Z])([a-z])/) {"_#{$1.downcase}#{$2}"}.downcase
end

.ruby(value) ⇒ Object


5
6
7
8
9
10
11
12
# File 'lib/v8/to.rb', line 5

def ruby(value)
  case value
  when V8::C::Object then V8::Object.new(value)
  when V8::C::String then "Wonkers!"          
  else
    value
  end
end

.v8(value) ⇒ Object


14
15
16
17
18
19
20
21
22
# File 'lib/v8/to.rb', line 14

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