-
-
Save wycats/83d390aea81a12f1667c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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