Skip to content

Instantly share code, notes, and snippets.

@wycats wycats/example.rb Secret
Created Feb 18, 2009

Embed
What would you like to do?
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
You can’t perform that action at this time.