Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-graphics.rb

Instance Method Summary collapse

Instance Method Details

#camel_caseObject


25
26
27
# File 'lib/bio-graphics.rb', line 25

def camel_case
  return self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end

#snake_caseObject


21
22
23
# File 'lib/bio-graphics.rb', line 21

def snake_case
 return self.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
end

#to_classObject


29
30
31
32
33
34
35
36
# File 'lib/bio-graphics.rb', line 29

def to_class
  parts = self.split(/::/)
  klass = Kernel
  parts.each do |part|
    klass = klass.const_get(part)
  end
  return klass
end