Class: Symbol

Inherits:
Object show all
Defined in:
lib/mustang/core_ext/symbol.rb

Instance Method Summary collapse

Instance Method Details

#to_js_func_nameObject

Returns symbol with function name normalized for javascript. eg:

:foo.to_js_func_name     # => :foo
:'foo='.to_js_func_name  # => :set_foo
:'foo!'.to_js_func_name  # => :foo_bang
:'foo?'.to_js_func_name  # => :is_foo
:'+'.to_js_func_name     # => nil


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mustang/core_ext/symbol.rb', line 10

def to_js_func_name
  js = self.to_s
  js = "set_#{js}" if js =~ /\=$/ 
  js = "#{js}_bang" if js =~ /\!$/ 
  js = "is_#{js}" if js =~ /\?$/ 
  js = js.gsub(/[^\w\d\_]+/, "")

  if js.empty? || (js == 'set_' && self.to_s != 'set_') 
    return nil
  else 
    return js.to_sym
  end
end