Skip to content

Instantly share code, notes, and snippets.

@wycats
Created February 18, 2009 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wycats/83d390aea81a12f1667c to your computer and use it in GitHub Desktop.
Save wycats/83d390aea81a12f1667c to your computer and use it in GitHub Desktop.
module Foo
module String
def to_s
super + "zilla"
end
end
end
use Foo::String for String
puts "God".to_s
end
#=> "Godzilla"
# merb-core/core_ext/string.rb
module Merb
module String
def camel_case
return self if self !~ /_/ && self =~ /[A-Z]+.*/
split('_').map{|e| e.capitalize}.join
end
end
end
# activesupport/core_ext/string.rb
module Rails
module String
def camel_case(first_letter = :upper)
case first_letter
when :upper then Inflector.camelize(self, true)
when :lower then Inflector.camelize(self, false)
end
end
end
end
# my_app.rb
"Hello".camel_case #=> NoMethodError
# my_app2.rb
use Merb::*
"hello_goodbye".camel_case #=> "HelloGoodbye"
"hello_goodbye".camel_case(true) #=> ArgumentError
end
use Merb::String for String
"hello_goodbye".camel_case #=> "HelloGoodbye"
"hello_goodbye".camel_case(true) #=> ArgumentError
end
# my_app3.rb
use Rails::*
"hello_goodbye".camel_case #=> "HelloGoodbye"
"hello_goodbye".camel_case(true) #=> nil
"hello_goodbye".camel_case(:lower) #=> "helloGoodbye"
end
use Rails::String for String
"hello_goodbye".camel_case #=> "HelloGoodbye"
"hello_goodbye".camel_case(true) #=> nil
"hello_goodbye".camel_case(:lower) #=> "helloGoodbye"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment